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


Please Help Members By Posting Answers For Below Questions

What are the differences between the servletconfig interface and the servletcontext interface?

845


What is the need of servlet filters?

736


How a servlet is unloaded?

800


The code in a finally clause will never fail to execute, right?

806


When Servlet is unloaded?

839


What are the advantages of servlets over traditional cgi?

814


How to upload a file to the server using servlet?

737


How to find whether a parameter exists in the request object?

877


Which HTTP method is non-idempotent?

807


How to read request headers from servlets?

796


Differentiate between the web server and application server?

765


What do you mean by request dispatcher in servlet?

861


What is difference between cookies and httpsession?

782


What do you mean by session tracking?

903


How do I support both get and post from the same servlet?

942