0

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>
Jitendra Kumar
  • 182
  • 2
  • 15
  • which class not found? if you dont mind can you paste stack trace? – SMA Nov 09 '14 at 11:26
  • Please do **not** use the Java default package (your Servlet is inside that default package) - this might solve your problem. See http://stackoverflow.com/questions/7849421/is-the-use-of-javas-default-package-a-bad-practice – home Nov 09 '14 at 11:30
  • I am handling the exception in signup.java file. this link gives error catch(ClassNotFoundException ex) { out.println("

    Servlet Error

    "); }
    – Jitendra Kumar Nov 09 '14 at 11:48
  • Stack track is not possible in this program because i run deploy this program on tomcat, and also i don't know how to do stack trace – Jitendra Kumar Nov 09 '14 at 11:50
  • @Mystery: regarding stacktrace - it's about printing the stacktrace using a logger or directly to the console. Please see e.g. http://stackoverflow.com/questions/6822968/print-the-stack-trace-of-an-exception – home Nov 09 '14 at 14:54

0 Answers0