import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet(“/IndexServlet”)
public class IndexServlet extends HttpServlet {
private static final long serialVersionUID=1L;
public IndexServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append(“Served at: “).append(request.getContextPath());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding(“utf-8”);
String user=request.getParameter(“user”);
String password=request.getParameter(“password”);
String path=request.getContextPath();
HttpSession session=request.getSession();
if (“1”.equals(user) && “1”.equals(password)) {
session.setAttribute(“name”, user);
response.sendRedirect(path + “/success.jsp”);
}else{
response.sendRedirect(path + “/Index.jsp”);
}
}
}