While running my application on tomcat server class not found exception occur in my windows 8.1 PC but this program run correctly in windows XP PC. My servlet application contains two java file and four html file. I have to run this application on windows 8.1 Operating System
Please do not use eclipse to run this Program
This is the signin.java file for the registered user.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class signin extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
PrintWriter out=res.getWriter();
String user=req.getParameter("un");
String pass=req.getParameter("ps");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mail");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from userinfo where user_name='"+user+"' and user_pass='"+pass+"' ");
if(rs.next())
{
ServletContext sc=getServletContext();
RequestDispatcher rd=sc.getRequestDispatcher("/welcome.html");
rd.forward(req,res);
}
else
{
ServletContext sc=getServletContext();
RequestDispatcher rd=sc.getRequestDispatcher("/error.html");
rd.forward(req,res);
}
}
catch(Exception ex)
{
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
doGet(req,res);
}
}//end of signin
This is the signup file for my new user.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class signup extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
PrintWriter out=res.getWriter();
String yr=req.getParameter("yn");
String un=req.getParameter("un");
String ps=req.getParameter("ps");
String sq=req.getParameter("sq");
String ans=req.getParameter("ans");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mail");
Statement st=con.createStatement();
st.executeUpdate("insert into userinfo values ('"+yr+"','"+un+"','"+ps+"','"+sq+"','"+ans+"')");
st.close();
con.close();
out.println("<h1>your account has been created successfully </h1>");
}
catch(SQLException ex)
{
out.println("<h1> User name is already present try with different name </h1>");
}
catch(ClassNotFoundException ex)
{
out.println("<h1> Servlet Error </h1>");
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
doGet(req,res);
}
}
And My Web.xml file
<web-app>
<display-name>Simple Servlet Program</display-name>
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>signup</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/xyz</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>pqr</servlet-name>
<servlet-class>signin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>pqr</servlet-name>
<url-pattern>/a</url-pattern>
</servlet-mapping>
</web-app>
Servlet Error
"); } – Jitendra Kumar Nov 09 '14 at 11:48