-1

I am creating one tool with JSP. I have multiple JSP pages which takes input from user. Now i want to use that inputs on many other jsp pages.

Suppose i have login page as my first page when user enters username i am able to get it on my next jsp page which i used in Form method as post action. But i am not able to display the same username on other Jsp Pages.

I am using jsp:getProperty for getting values:

<jsp:getProperty property="username" name="user2"/><br> 
<jsp:getProperty property="password" name="user2"/><br> 

Please suggest is there any way to get the value on multiple pages with jsp:useBean

Thomas
  • 87,414
  • 12
  • 119
  • 157
shilpa
  • 9
  • 1
  • 5

4 Answers4

0
    <% HttpSession httpSession = request.getSession();
            httpSession.setAttribute("user2", user2);
    %>

    then from any jsp page u can access that attribute for same session like this

   <%HttpSession httpSession=request.getSession();
         httpSession.getAttribute("user2");
   %>
Sumeet
  • 87
  • 1
  • 10
  • i tried using it as but then it is not at all working . with scope="page" it at least work for next page. – shilpa Mar 31 '16 at 13:25
  • <% HttpSession httpSession = request.getSession(); httpSession.setAttribute("user2", user2); %> this need to be added in servlet right ?? – shilpa Apr 11 '16 at 09:50
0

Yes we can do it by passing value through sessions. Like given below request.getSession().setAttribute("key", <value>);

0

You can store your bean in the session so it is directly accessible from your JSP. (see this answer on SO).

Your bean declaration should be something like:

<jsp:useBean id="user2" class="mycompany.User" scope="session" />

If you want to really persist the data, you should store in a database.

Note that you should consider MVC frameworks such as Spring MVC or Apache Struts but you will have to assimilate lots of concepts.

Community
  • 1
  • 1
C.Champagne
  • 5,381
  • 2
  • 23
  • 35
-1

Yes you can access it in this way:

login.jsp:

    <form action ="process.jsp">
    Username:
    <input type="text" name="username">
    Password:
    <input type="password" name="password">
<input type="submit" value="Submit">
    </form>

process.jsp:

    <% String username = request.getParameter("username");
       String password = request.getParameter("password");
     %>
Muhammad Ilyas
  • 169
  • 1
  • 13