简体   繁体   中英

can't call servlet from jsp page form

I have JoinCustomerToAccountServlet servlet under src/controller -

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

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

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:

<form action="../JoinCustomerToAccountServlet" to make it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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