aspose file tools*
The moose likes Struts and the fly likes JSP - Servlet interaction. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JSP - Servlet interaction." Watch "JSP - Servlet interaction." New topic
Author

JSP - Servlet interaction.

Amit Shanker
Greenhorn

Joined: Mar 08, 2003
Posts: 23
Hi All,

I have a JSP page which has plenty of form variables. Now I want the form to submit to a servlet(say for validations!) which will do all the processing and return back to the JSP. How can my JSP page access the request parameters of the form variables?

Any suggestions?

Regards,

Amit.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Put everything in a session object, submit them to a servlet, validate them in the servlet and forward it to the target JSP... Using session object can help you a lot in manipulating a bunch of parameters...

But I feel this kind of question belongs to the JSP or Servlet forums out there... Anyway, before it is moved to those forums, I hope my reply helps you at least...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Amit Shanker
Greenhorn

Joined: Mar 08, 2003
Posts: 23
Yes..storing them in sessions is definitely one option. But imagine this servlet to be a "ProcessingServlet" for all the forms in JSPs(all JSPs submitting values to this servlet). There is an overhead of removing these attributes after completion of processing. Currently we use an include JSP which does this job. I was just wondering if JSPS are eventually compiled as servlets, why can't we persist or forward the request parameters back to the calling JSP??

Thanks,
Amit.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
What do u mean by "an overhead of removing these attributes after completion of processing"? If you use an include JSP instead of that servlet, does it mean that there is no overhead? I do believe that servlet is better in performance than JSP, as you also said that JSPs are eventually compiled as servlets, in which the compilation of JSP take some time as well... So I think using servlet instead of dealing with JSP is better....

But if you use the way that forwards request parameters back to the calling JSP, you need to change every single JSP in your application... And it is not a proper way for form validation things...

I guess some other ranchers might got a better approach than us....
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
why can't we persist or forward the request parameters back to the calling JSP??


Please post your error message.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
I was just wondering if JSPS are eventually compiled as servlets


This is normally process .

1. First request to JSP file : Web Container generate servlet file from jsp page and compile thsi file .... and work follow step in jsp file.

2. Another request : Web Container not generate servlet file.


So, first time is slow than another request to jsp file.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by somkiat puisungnoen:


Please post your error message.


Mr.Somkiat,
There is no error in Amit's implementation... I guess you might be misunderstanding the things that we are talking about... We just need any other approach to deal with it...
Amit Shanker
Greenhorn

Joined: Mar 08, 2003
Posts: 23
Hi All,

I had my thoughts mixed up! After the post, I realised that an include JSP (static) eventually gets compiled into a single servlet :-);but while submitting parameters to a servlet and redirecting back to the original JSP, these are two different servlets interacting. So the only option would be to set return values in session and pass them back to the JSP.

Thank you for your responses.

Cheers,
Amit.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Amit Shanker:
Hi All,

I had my thoughts mixed up! After the post, I realised that an include JSP (static) eventually gets compiled into a single servlet :-);but while submitting parameters to a servlet and redirecting back to the original JSP, these are two different servlets interacting. So the only option would be to set return values in session and pass them back to the JSP.

Thank you for your responses.

Cheers,
Amit.

It's good that you can figure it out after all.. As I mentioned before, using a servlet as a controller of validation in this context is pretty good design as well as the performance of ur web app...

So cheers!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP - Servlet interaction.