Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP as a blueprint for several webpages  RSS feed

 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello forum,
i would like to know how to call a JSP-file with different parameters so that I can use it as a blueprint for several webpages in my project.

My project is quite simple and only for learning purposes:
I have a start page with several cooking recipes. If I click on one of those recipes I will get a detailed view of the recipe, which includes some text and an image. However, I don't want to create a new jsp-file for every recipe, because all recipes have the same layout. Instead, I want to use one and the same jsp-file for an arbitrary amount of recipes. The content of those recipes should be located in one or several XML-files.

I couldn't find a good example on the internet, so I would be very happy if someone could help me here.
 
Palak Mathur
Ranch Hand
Posts: 342
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Zuckermann wrote:Hello forum,
i would like to know how to call a JSP-file with different parameters so that I can use it as a blueprint for several webpages in my project.

My project is quite simple and only for learning purposes:
I have a start page with several cooking recipes. If I click on one of those recipes I will get a detailed view of the recipe, which includes some text and an image. However, I don't want to create a new jsp-file for every recipe, because all recipes have the same layout. Instead, I want to use one and the same jsp-file for an arbitrary amount of recipes. The content of those recipes should be located in one or several XML-files.

I couldn't find a good example on the internet, so I would be very happy if someone could help me here.


It is a simple dynamic page that you are creating. Query the xml and put the things at the correct position in Jsp.
 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The XML should be parsed with JavaScript, but I don't know how to call one JSP with different parameters where each parameter fills the JSP-page with different content.

Normally I would have something like that:



Instead of calling page2.jsp, I would like to call page1.jsp with other parameter values.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the content is different, why would you not use two pages?

In any case, you don't "pass parameters" to a JSP. Rather, you can set data as scoped variables in request scope (or other scopes) that the page can use to make decisions or display dynamic data.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use jsp:include and jsp:param as given in this example:

http://www.roseindia.net/jsp/jsp-include-param.shtml

WP
 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea is that I have one jsp-page for a whole set of webpages so that I can easily modify the design for a large amount of webpages. Otherwise I would have one jsp-page for every single recipe and altering all those files could be tedious.



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bad approach. CSS should be used to apply similar styling to multiple pages, and for sharing layout, that's what project such as Tiles and SiteMesh are for.

I would strongly advise against the approach you are taking, and also against using anything you see at roseindia as a good example. That sire is notorious for giving uniformly awful advice and examples.
 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if such a design is good, but it's just for educational purposes. The main task is to call one jsp-page with different content that is located in an XML-file.

Is it better to parse XML on the client or on the server?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Better" is always subjective and impossible to say without knowing a lot more.

I do either, depending upon circumstances.
 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Server-side parsing could have the disadvantage of slowing the server down if many requests appear at the same time. Client-side parsing might cause security problems. Is there a general guideline when to use which approach?
One part of the task is to generate beans from the XML file. Could this be done easier on the server-side?


I am still wondering how I could accomplish the main task. Maybe each link should be associated with an ID-variable, but I don't know how the architecture might look like.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!