我有一张表格
<form method="POST" action="${pageContext.request.contextPath}/validate">
Username: <input type="text" name="username" id="username"/><br />
Password: <input type="password" name="password" id="password"/><br />
<input type="submit" value="Submit" id="btnSubmit"/>
<input type="reset" value="Clear" id="btnClear"/>
</form>
预计会发布到validate.java
servlet
的web.xml
<web-app>
<servlet>
<servlet-name>validate</servlet-name>
<servlet-class>springapp.validate</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>validate</servlet-name>
<url-pattern>/validate</url-pattern>
</servlet-mapping>
</web-app>
文件夹结构
validate.java包含一个简单的重定向
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
response.setContentType("text/html");
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username.equals("admin") && password.equals("pass")){
response.sendRedirect("Main.jsp");
}
else{
response.sendRedirect("index.jsp");
}
}