Joseph Seah wrote:
>
> Hi...
>
> Have been trying to get my JSP to read info from my bean instance....but
> can't seem to do so.  Need some advice.

That's because you save the bean in the session using the name "ccenquiry.loginuser"
but you try to get it in the JSP page using the name "loginUser".

Your useBean id attribute value and getProperty name value must match the
name you use in session.putValue().

Hans

> Below are my rough codes.
>
> I have a form(Parameters are: userId and passwd) that submits to my
> LoginServlet.
>
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import ccenquiry.LoginBean;
>
> public class LoginServlet extends HttpServlet {
>         public void init(ServletConfig conf) throws ServletException {
>                 super.init(conf);
>         }
>
>         public void doPost(HttpServletRequest req, HttpServletResponse res) throws
> ServletException, IOException {
>
>                 HttpSession session = req.getSession(false);
>                 if (session == null) {
>                         res.sendRedirect("http://localhost:8080/ccEnqError.htm");
>                 }
>
>                 if ((req.getParameter("userId") != null) && 
>(req.getParameter("passwd") !=
> null)) {
>                         // instantiates the LoginBean.
>                         LoginBean loginUser = new LoginBean();
>                         loginUser.setUserId(req.getParameter("userId"));
>                         loginUser.setPasswd(req.getParameter("passwd"));
>
>                         if (true) {
>                                 session.putValue("ccenquiry.loginuser", loginUser);
>                                 String address = "/jsp/ccenquiry/banner.jsp";
>                                 ServletContext sc = getServletContext();
>                                 RequestDispatcher rd = 
>sc.getRequestDispatcher(address);
>                                 rd.forward(req, res);
>                         }
>                 }
>         }
> }
>
> Below is my banner.jsp
>
> <%@ page import="ccenquiry.LoginBean" session="true" info="banner" %>
>
> <jsp:useBean id="loginUser" scope="session" class="ccenquiry.LoginBean" />
>
> <html>
> <body>
>
> <!-- start banner table -->
> <table width=600 align=center>
> <tr>
>         <td align=center><font size=2 face="Lucida Sans Unicode">User Id is:
> <jsp:getProperty name="loginUser" property="userId" /></font></td>
> </tr>
> </table>
> <!-- end banner table -->
>
> </body>
> </html>

--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to