无法从jsp页面表单调用servlet

时间:2012-08-10 10:31:12

标签: java forms jsp servlets submit

我在JoinCustomerToAccountServlet -

下有src/controller个servlet
@WebServlet("/JoinCustomerToAccountServlet")
public class JoinCustomerToAccountServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {


    }

}

joinCustomerToAccount.jsp -

下列出WebContent/ActionsPages
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
        <form action="JoinCustomerToAccountServlet" method="POST">
            Account join to him : <input type="text" name="account" />
            <input type="submit" value="join" />

</body>
</html>

填写完表格后按下提交按钮我

type Status report

message /MyBankProject/ActionsPages/JoinCustomerToAccountServlet

description The requested resource (/MyBankProject/ActionsPages/JoinCustomerToAccountServlet) is not available.

它看起来像在他的文件夹下搜索表单而不是搜索servlet。

1 个答案:

答案 0 :(得分:2)

由于您的网址映射为/JoinCustomerToAccountServlet,并且您的JSP位于/MyBankProject/ActionsPages内,因此您必须将表单的操作更改为:

<form action="../JoinCustomerToAccountServlet"让它发挥作用。