找不到类servlet程序中的异常(Windows 8.1错误)

时间:2014-11-09 11:16:44

标签: servlets

在我的Windows 8.1 PC上运行我的应用程序在tomcat服务器类上找不到异常,但此程序在Windows XP PC中正常运行。 我的servlet应用程序包含两个java文件和四个html文件。我必须在Windows 8.1操作系统上运行此应用程序

请不要使用eclipse来运行此程序

这是注册用户的signin.java文件。

    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

这是我的新用户的注册文件。

    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);
        }
    }

我的Web.xml文件

<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>

0 个答案:

没有答案