简体   繁体   English

无法从jsp页面表单调用servlet

[英]can't call servlet from jsp page form

I have JoinCustomerToAccountServlet servlet under src/controller - 我在src/controller下有JoinCustomerToAccountServlet servlet -

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


    }

}

And form joinCustomerToAccount.jsp under WebContent/ActionsPages - 并在WebContent/ActionsPages下形成joinCustomerToAccount.jsp -

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

After I fill the form and press on the submit button I get 在我填写表格并按下提交按钮后,我得到了

type Status report

message /MyBankProject/ActionsPages/JoinCustomerToAccountServlet

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

It looks like the form searching under his folder and not search for servlet . 它看起来像在他的文件夹下搜索表单而不是搜索servlet。

Because your URL mapping is /JoinCustomerToAccountServlet and because your JSP resides inside /MyBankProject/ActionsPages , you'll have to change your form's action into this: 因为您的URL映射是/JoinCustomerToAccountServlet并且因为您的JSP位于/MyBankProject/ActionsPages ,所以您必须将表单的操作更改为:

<form action="../JoinCustomerToAccountServlet" to make it work. <form action="../JoinCustomerToAccountServlet"使它工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM