servlet代码:
package com.wjrong.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String host="/index.jsp";
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("username");
String password=request.getParameter("password");
if(name.equals("jack") && password.equals("abcd")){
host="/welcome.jsp";
}
request.getRequestDispatcher(host).forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}