Hi frnds iam new to Java Kindy any one can provide or me
Servlets Example code and can explain to me flow of servlets
and as Jsp and Struts and provide to me some sample example
on these 3 topic flow,code example,and tutorials,and related
websites which i can refer....thanks in advance..........
Answer Posted / sarang
hi friend,this is sarang
following is the code for sevlet,i used net beans editor....
package javas;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class emp extends HttpServlet
{
public void init(ServletConfig config)throws
ServletException
{
super.config();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
}
catch(Exception e)
{
throw Exception(e.gerMessage())
}
}
public void doGet(HttpServletRequst
req,HttpServletResponse res)
throws IOException,ServletException
{
String pass=req.getParameter("password");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body>");
Connection con=null;
try
{
con=DriverManager.getConnection();
}
catch(SQL Exception e)
{
throw Exception("SQL Exception"+e.getMessage());
}
Statement stmt=null;
ResultSet rs=null;
try{
stmt=con.CreateStatement();
rs=stmt.executeQuery("select password,uname from t1
where pass=admin");
if(pass=="admin");
pw.println("welcome");
else
pw.println("try again!!!");
pw.println("</body>");
pw.println("</html>");
}
catch(Exception e)
{
out.println("Exception is"+e.gerMessage());
}
out.close();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What are the differences between the servletconfig interface and the servletcontext interface?
What is the need of servlet filters?
How a servlet is unloaded?
The code in a finally clause will never fail to execute, right?
When Servlet is unloaded?
What are the advantages of servlets over traditional cgi?
How to upload a file to the server using servlet?
How to find whether a parameter exists in the request object?
Which HTTP method is non-idempotent?
How to read request headers from servlets?
Differentiate between the web server and application server?
What do you mean by request dispatcher in servlet?
What is difference between cookies and httpsession?
What do you mean by session tracking?
How do I support both get and post from the same servlet?