Solved

Question on passing values from Servlet TO JSP

Posted on 2002-03-20
4
195 Views
Last Modified: 2013-11-24
I am currently working on a web project that has employed Model 2, wcich is recommended in the specification.
Servlet receives http request and do some work and return
Jsp pages and blah blah...

Question to seasoned experts is as following.

I use the session as interim "basket" to hold the
process results. In other words, Servlet puts the "result"
as an session property(Attribute), then JSP pages uses it
while rendering the page to be displayed. As a project
gets bigger, I have more tedious tasks to keep all
"resulting objects" in order.
I am wondering what architecture or methods other experts
are using in this situation.

I appreciate all comments and advises.

Have a good one...

JY



0
Comment
Question by:joshuayoo
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
pellep earned 300 total points
Comment Utility
Well, i'm not sure what you're after here. There is no 'magic' to good design. Especially JSP can and do tend to get rather complex as each 'page' may get built by several JSP pages through includes and such.

I guess the only way to go about it (providing you are aiming for a somewhat homogenues design) is to try and think through and identity what specific information needs to be maintained across sessions and request and then enforce that throughout the development. One 'semi-hack' (and I call it that because it's not really within the servlet spec) i've used with great success is the create a 'holder' class with attributes for all values/objects/information that pertains to your site. Create a single instance of this class as the session/request is first created and store the object i your session/request. This way, you have a 'fixed' method of storing/retreiving your information. At least it saves you the agony of having to maintain a design involving zillions of property names in string format.

Anyways, my two cents...
0
 
LVL 1

Expert Comment

by:skinsella
Comment Utility
instead of using the session, consider using the request.setAttribute() and request.getAttribute().

If the objects created in the servlet are only needed for the resulting JSP, then put them into the request context, and you don't have to worrya bout cleaning them up subsequently.

sean
0
 

Author Comment

by:joshuayoo
Comment Utility
Thanks for comments, pellep.

Actually, that is what I am doing right now. I was
wondering if I am doing it right. Your comments assured
me that I am doing ok. I wish I had more comments on this.
Well, I think it is time to wrap up and close it down.
I will appreciate if you have more comments.

JY



skinsella, sorry that my question was obscure. I was
working on session-bound data passing...I did not
clearly mention it. I thank you for your comment.



0
 
LVL 4

Expert Comment

by:pellep
Comment Utility
I'm glad I could raise your confidence in your design. At the end of the day, you have to be comfortable with your design, or you'll have a hard time implemeting it. Good luck!

/Par
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now