Servlet:请求的资源()不可用

时间:2014-02-21 16:41:10

标签: javascript jsp servlets netbeans

我在2台不同的计算机上完成我的毕业设计项目,问题是每次我从这里复制到那里我会遇到无休止的错误和问题,特别是提交servlet,例如我有一个注册表单,通过注册用户信息servlet到另一个连接到另一个数据库,当我在其中一台计算机上尝试它工作正常但现在我把它带回家我得到所请求的资源()不可用。错误。

这是注册JSP表单方法并提交

<form name="myForm" action="RegisterUSER" onsubmit="return validateForm()"            method="post">

这里我有所有的注册字段和下拉框,而且我有这个

   <input type="submit" value="Register" name="Register" />
   </br>
   </form>

这是它应该提交给的servlet(一个netbeans无法找到)。

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class RegisterUSER extends HttpServlet {


    protected static void processRequest(HttpServletRequest request, HttpServletResponse   response)
   throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        String First_Name=request.getParameter("FirstName");
        String Middle_Name=request.getParameter("MiddleName");
        String Last_Name=request.getParameter("LastName");
        String Username=request.getParameter("Username");
        String Email_Address=request.getParameter("EmailAddress");
        String Password=request.getParameter("Password");
        String Birth_date=request.getParameter("Birthdate");
       String ID=request.getParameter("ID");

    Connecttodatabase con=new Connecttodatabase();
    int x=0;
    try{
 x =con.insertusersToDatabase(First_Name, Middle_Name, Last_Name, Username, Email_Address, Password, Birth_date, ID);
    }
     catch(Exception e){
            System.err.println("Got an exception!");
            System.err.println(e.getMessage());
         }
out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet Registration</title>");
        out.println("</head>");
        out.println("<body>");
        request.getContextPath ();
       out.println("Registration Complete " +x);
       out.println(Username);

        out.println("</body>");
        out.println("</html>");

        out.close();
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        try{
        processRequest(request, response);
        } catch(Exception e){
            System.err.println("Got an exception!");
            System.err.println(e.getMessage());
         }
    }

    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        try{
        processRequest(request, response);
        } catch(Exception e){
            System.err.println("Got an exception!");
            System.err.println(e.getMessage());
         }
    }

    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}

1 个答案:

答案 0 :(得分:0)

容器无法将URL映射到servlet。问题可能出在你的web.xml中。