Here is my index.jsp
code:
<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>
Here is my IndexController
Servlet code:
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);
}
}
Here is my welcome.jsp
page code
<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>
When I run this through the Java EE runtime, I got an index.jsp
page, but after I entered a name and clicked a submit button, I got the following error:
Error 404 - Not Found No context on this server matched or handled this request. Contexts known to this server are: JSPExample(/JSPExample)
Also change the line in welcome.jsp <% String fname = request.getParameter("**uname**");%>
to <% String fname = request.getParameter("**name**");%>
, since your parameter name is name
response.sendRedirect("**welcome.jsp?name="+uname);**
:)