Solved

Question on passing values from Servlet TO JSP

Posted on 2002-03-20
4
207 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 104
Spring Framework HTTPSession management 1 33
HashTable highest marks enumeration alternative 9 37
servlet example issue 6 38
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

786 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