我有一个主页,其中有一个标题、一个侧边栏和一个 div 标签。当用户点击“注册”时,Registration.jsp
被加载到 div 标签中。
成功提交注册表单后,我想将其转发到我想在 div 标签中显示 html“bookimages.html”的同一页面。
我尝试设置一个属性值来执行此操作。
这是我的 mainpage.css:
<body id="userprofilepage">
<% request.setAttribute("regisstatus",null); %>
<div>
<%@ include file="header.jsp" %><br>
</div>
<div id="mainsidebar">
<%@ include file="sidebar.html" %>
</div>
<div>
<%@ include file="priviledges.html" %>
</div>
<div id="contentarea">
<% if(request.getAttribute("regisstatus")==null)
{ %>
<%@ include file="bookimages.html" %>
<% } else if((request.getAttribute("regisstatus").toString()).equals("success")) { %>
<%@ include file="Register.jsp" %>
<% } else { %>
<h3>Sorry could not register.. Try again</h3>
<% } %>
</div>
</body>
jQuery
在我的标题中,我有一个注册按钮:
$(function(){
$("#register").click(function(){
$("#contentarea").load("RegistrationServlet.jsp");
});
});
...工作正常。并调用 RegistrationServlet.java:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//Takin all parameters
String fname = request.getParameter("fname");
//System.out.println(fname);
String lname = request.getParameter("lname");
//System.out.println(lname);
String mobileno = request.getParameter("mobno");
//System.out.println(mobileno);
String pwd = request.getParameter("password");
//System.out.println(uid);
// String cpwd = request.getParameter("password");
//System.out.println(pwd);
String email = request.getParameter("email");
String off_add= request.getParameter("off_add");
String perm_add = request.getParameter("perm_add");
String[] r = request.getParameterValues("role");
for(int i=0;i<r.length;i++)
{
System.out.println(r[i]);
}
ArrayList<Integer> role=new ArrayList<Integer>();
for(int i=0;i<r.length;i++)
{
Integer r1=new Integer(RoleManager.getRoleid(r[i]));
role.add(r1);
}
/*for(int i=0;i<r.length;i++)
{
Integer r1=new Integer(RoleManager.getRoleid(r[i]));
role.add(r1);
}*/
String g[]=request.getParameterValues("genre");
ArrayList<Integer> genre=new ArrayList<Integer>();
for(String i : g)
{
Integer g1=new Integer(GenreManager.getGenreid(i));
genre.add(g1);
}
// creating user object
RegisteredUser uobj = new RegisteredUser();
//setting values in RegisteredUser obect
uobj.setFname(fname);
uobj.setLname(lname);
uobj.setPassword(pwd);
uobj.setMobileno(mobileno);
uobj.setPassword(pwd);
uobj.setEmail(email);
uobj.setOffadd(off_add);
uobj.setPermadd(perm_add);
uobj.setRole(role);
uobj.setGenre(genre);
uobj.setUid("abc2");
//send user object to manger
boolean suc=UserManager.createUser(uobj);
System.out.println("user object created");
if(suc)
request.setAttribute("regisstatus", "success");
else
request.setAttribute("regisstatus", "fail");
RequestDispatcher rd=request.getRequestDispatcher("/userprofilepage.jsp");
rd.forward(request, response);
}
}
但是在我的主页中,请求属性没有被设置。你能帮我找出问题吗?