如何验证用户身份并将其重定向到他自己的页面,即 www.mysite.com/“用户的电子邮件”。
我正在使用以下不起作用的算法...
用户类中的 userDB:
Map<String,String> userdata=new HashMap<String,String>();
首先我的登录流程表格:
@Path("/login")
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void login(
@FormParam("email") String emailc,
@FormParam("password") String pass,
@Context HttpServletResponse servletResponse
) throws IOException,RuntimeException {
User u1=new User();
pass=u1.getPassword();
emailc=u1.getEmailaddrs();
boolean checked=false;
boolean exists;
exists=u1.userdata.containsKey(emailc);
if(exists){
String mypass =u1.userdata.get(emailc);
if(mypass==pass){
checked=true;
}else{
checked=false;
}
}else{
checked=false;
}
if(!checked){
//User Doesn't exists
servletResponse.sendRedirect("http://localhost:8080/MySite/pages/Create_Profile.html");
}else{
servletResponse.sendRedirect("http://localhost:8080/MySite/{email}"); <<<< How to redirect using @FormParam("email")
}
}
创建个人资料
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newUser(
@FormParam("email") String email,
@FormParam("password") String password,
@Context HttpServletResponse servletResponse
) throws IOException {
User u = new User(email,password);
User.userdata.put(email,password);
}