Solved

Question on passing values from Servlet TO JSP

Posted on 2002-03-20
4
219 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
ID: 6884200
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
ID: 6888120
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
ID: 6888748
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
ID: 6888781
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

763 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