How To Set Scope Of Bean Through Servlet
My Problem is i am using a bean which stores the information of logged in member .
Now when a user enters throgh a jsp page a servlet is called in between now after necessary validations i am setiing this info in a bean .
String xxx = req.getParameter("xxx");
Bean1 b1 = new Bean1();
b1.setName(xxx);
HttpSession session = req.getSession();
session.setAttribute("Bean1",b1);
Now in the preceding jsp page when i try to reterive this info :
<jsp:useBean id="b1" class="Bean1" scope="session" />
<jsp:getProperty name="b1" property="name" />
i dont get anything;
Please anybody could help.
My first jsp page :
jsp1.jsp
<HTML>
<BODY bgcolor="#408080" text="#FFFF00">
<input type="Text" name="name">
</BODY>
</HTML>
Intermediate servlet :
servlet1.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class servlet1 extends HttpServlet
{
Bean1 b1 = new Bean1();
public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
String name = req.getParameter("name");
b1.setName(name);
HttpSession session = req.getSession();
session.setAttribute("Bean1",b1);
String nu = "../jsp2.jsp?name="+name;
res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
res.setHeader("Location",nu);
}
}
Bean Page :
import java.io.Serializable;
public class Bean1 implements Serializable
{
String name = "";
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}
My Second Jsp Page :
jsp2.jsp
<HTML>
<BODY>
<jsp:useBean id="b1" class="Bean1" scope="session" />
<jsp:getProperty name="b1" property="name" />
</BODY>
</HTML>
but this returns nothing .