This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line! See this thread for details.
<FORM METHOD="POST" ACTION="/genericacg/Display.jsp"> FirstName<input type="text" value="" name="fname"><br> Last Name <input type="text" value="" name="lname"><br> <INPUT TYPE="SUBMIT" VALUE="SENT" NAME="GO" > </FORM> </body> </html> --------------- Display.jsp <%@page contentType="text/html"%> <html> <head><title>JSP Page</title></head> <body> <jsp:useBean id="empData" scope="session" class="EmpBean" /> <jsp:setProperty name="empData" property="*" /> <%= empData.getFname() %><br> <%= empData.getLname() %><br> <FORM METHOD="POST" ACTION="/genericacg/Salary.jsp"> Salary<input type="text" value="" name="salary"><br> <INPUT TYPE="SUBMIT" VALUE="SENT" NAME="GO" > </FORM> </body> </html> ------------- Salary.jsp <%@page contentType="text/html"%> <html> <head><title>JSP Page</title></head> <body> <jsp:useBean id="empData" scope="session" class="EmpBean" /> <jsp:setProperty name="empData" property="*" /> <%= empData.getFname() %><br> <%= empData.getLname() %><br> <%= empData.getSalary() %><br> </body> </html> --------------- Now my starting point is EmpData.jsp When I click on the "submit" button on this page i get Display.jsp which shows the Employee Fname and last name and collects info about the salary. When I click on te "submit" on Display.jsp I get Salary.jsp. Which shows the FName and LName as null but shows the Salary entered in Display.jsp. My problem is even though I maintain the scope of the bean as "session" it does not persist across different jsp pages.Instead a new bean is created when I access a diff jsp page. I want the bean data to persist during a session.Is my method of doing it incorrect?Could someone guide me towards the right way of doing this. Thanks Ruplai Desai
Please could someone guide me as to what is wrong with the following code:
Well, this is not the problem you were asking about, but one very serious problem with the above is the lack of packages. It is not guaranteed to work if you use packageless beans with jsp:useBean. Even worse, by luck it sometimes does work. Here is a question: in general in Java, when you refer to a class and use neither a fully scoped name (ie with packages included) nor import statements, what package does the system think that class is in? Answer: the same package as the current class! Here is another question: when a JSP page gets translated into a servlet, what package will it be in? Answer: unknown! See the problem? So, a packageless bean will work only if the servlet happens to also be packageless, but there is no standard that governs this. Most versions of Tomcat generate packageless servlets for JSP pages that are in the top-level directory of the Web app, but use packaged servlets for JSP pages that are in subdirectories. But that is just how the current Tomcat implementation happens to work: this is totally unspecified by the spec. Let me say this as clearly as I can, since failing to do so causes all sorts of problems: Always, always, always put all beans and utility classes in packages. When using a bean from JSP, use <jsp:useBean ... class="packageName.BeanName".../> . Cheers- - Marty
Hi, The code is working fine with me.I have OC4J and jdk1.3.1_04. What web container are u using? Only changes i made in code are :- changed form action in EmpData.jsp to <FORM METHOD="POST" ACTION="Display.jsp"> and changed form action in Data.jsp to <FORM METHOD="POST" ACTION="Salary.jsp"> as all files are in same directory.But, it shouldnt matter. HTH, Piyush
"A scientist is not person who gives right answers but a person who asks right questions"
posted 17 years ago
Hello, Well I got it to work with Tomcat 3.2.For some reason it never worked with tomcat 3.3.I even tried reinstalling toncat 3.3. I am going to try an dtest with tomcat 4.1. But anyone it works fine with tomcat 3.2. Thanks for all the help. Rupali Desai
My pie came with a little toothpic holding up this tiny ad: