简单的J2ee程序无效

时间:2016-01-19 06:29:37

标签: java jsp servlets

this is structure of project 此servlet位于servlet包

package Servlets;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class OpenAccountServlet extends HttpServlet {
    public void init(ServletConfig config) throws ServletException{
        super.init(config);
    }
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
        response.setContentType("text/html");
        PrintWriter out= response.getWriter();
        String firstName=request.getParameter("firstname");
        String lastName=request.getParameter("lastname");
        String fatherName=request.getParameter("fathername");
        String webPage=null;
        webPage+="<html>";
        webPage+="<head>";
        webPage+="</head>";
        webPage+="<body>";
        webPage+=firstName;
        webPage+=lastName;
        webPage+=fatherName;
        webPage+="</body>";
        webPage+="</html>";
        out.println(webPage);
        out.close();
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
        doGet(request,response);
    }
    public void destroy(){

    }
}

这是我用来接受用户数据的jsp页面。

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
  <form method="post" action="openaccount.do">
    <table>
      <tr>
        <td>First Name</td>
        <td><input type="text" name="firstname" value=""></td>
      </tr>
      <tr>
        <td>Last Name</td>
        <td><input type="text" name="lastname" value=""></td>
      </tr>
      <tr>
        <td></td>
        <td><input type="submit" name="submit" value="Submit">
          <input type="button" name="cancel" value="Cancel">
        </td>
      </tr>
    </table>
  </form>
</body>
</html>

,这是我的web.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <servlet>
        <servlet-name>Open_Account_controller</servlet-name>
        <servlet-class>Servlets.OpenAccountServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Open_Account_controller</servlet-name>
        <url-pattern>/openaccount.do</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

每当我试图运行它时,404错误。我正在使用intelliJ idea IDE进行开发,我正在使用64位tomcat。

1 个答案:

答案 0 :(得分:0)

尝试Base 64
删除前导<form method="post" action="../openaccount.do">时会尝试加载相对于当前目录的URL。

更好的是使用更通用的形式,如:
../