此服务器上没有上下文匹配

Buc*_*cks 5 java jsp servlets

这是我的index.jsp代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index JSP File</title>
</head>
<body>
<form action="/IndexController" method="get">
<table>
<tr><td>Enter Your Name :</td> <td><input type="text" name="name"/></td></tr>
<tr><td><input type="submit" value="Submit" /></td></tr>
</table>
</form>
</body>
</html>   
Run Code Online (Sandbox Code Playgroud)

这是我的IndexControllerServlet代码:

public class IndexController extends HttpServlet {

    protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uname = request.getParameter("name");
        response.sendRedirect("welcome.jsp?name="+uname);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doProcess(request, response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doProcess(request, response);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的welcome.jsp页面代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<% String fname = request.getParameter("uname");%>
<h1>Welcome to JSP World,  <%=fname%></h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我通过Java EE运行时运行时,我得到了一个index.jsp页面,但在输入名称并单击提交后,我收到以下错误:

Error 404 - Not Found No context on this server matched or handled this request. Contexts known to this server are:  JSPExample(/JSPExample)
Run Code Online (Sandbox Code Playgroud)

Lee*_*joy 0

还将welcome.jsp 中的行更改<% String fname = request.getParameter("**uname**");%><% String fname = request.getParameter("**name**");%>,因为您的参数名称是name response.sendRedirect("**welcome.jsp?name="+uname);**:)