This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp/servlet design problem  RSS feed

 
Daren Reavis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please bear with me, I am still pretty new to Java. I am trying to create a web report with JSP and Servlets under Tomcat5. This reports has several independent pieces, so I would like to make the report modular, with a servlet for each piece to perform the necessary data access and logic.

I was hoping to design it in the following way: Each servlet would perform it's logic, write the results to a bean, and then forward to a JSP Fragment (.jspf). Then I would have a main JSP page that would just include each servlet that I needed (hence getting the output from the JSP Fragments). That way I could add or remove each piece with ease from the JSP.

I have begun to realize, however, that this doesn't work. Because of the nature of JSPs & Servlets, the jspf that the servlet forwards to doesn't get parsed. Instead, it's code is written to the browser where it is included. I obviously need to change the way I'm doing things, but I am not sure how. How do I keep this modular? Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you naming the JSPs that you are forwarding to as fragment files? That should be reserved for files inlcuded using a static include directive.

Your issue may be as simple as renaming the files to .jsp.
 
Daren Reavis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!! You were right. All I needed was to do was make the jspf a jsp, and it started working. Thanks again!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daren Reavis:

... Because of the nature of JSPs & Servlets, the jspf that the servlet forwards to doesn't get parsed. Instead, it's code is written to the browser where it is included.


This is not correct.
If your JSP code is ever sent to the browser something is wrong.
As Bear mentioned, and you have probably noticed, jspf files are parsed on the server; but only when they are statically included.

When you get a chance, read this entry in our JspFaq. It covers the difference between the two include mechanisms in JSP.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!