我创建了两个servlet页面,第一个servlet页面是RegistrationServlet,第二个servlet页面是LoginServlet,并为链接列表创建了一个对象,以便从其他servlet调用它,但是我无法调用该对象。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
String name,email,pass;
name=request.getParameter("un");
email = request.getParameter("em");
pass = request.getParameter("pass");
LinkedList<String> a1=new LinkedList();
a1.add(name);
a1.add(pass);
if (!name.isEmpty() && !email.isEmpty() && !pass.isEmpty()) {
RequestDispatcher rd=getServletContext().getRequestDispatcher("/Login.html");
rd.forward(request, response);
request.getSession().setAttribute("someone", a1);
request.getRequestDispatcher("LoginServlet").forward(request, response);
} else {
RequestDispatcher rd1 = getServletContext().getRequestDispatcher("/Register.html");
rd1.include(request, response);
}
}
Other Servlet---------------------------------------
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
String email = request.getParameter("eml");
String pass = request.getParameter("pass");
object fg;
fg = request.getSession().getAttribute("someone");
if(email.equals(fg.a1.get(0)) && pass.equals(fg.a1.get(1)))
{
System.out.println("sucess");
}
else{
System.out.println("not");
}
}