aspose file tools
The moose likes JSP and the fly likes JSP as a blueprint for several webpages Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "JSP as a blueprint for several webpages" Watch "JSP as a blueprint for several webpages" New topic
Author

JSP as a blueprint for several webpages

Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 45
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

Joined: Jan 29, 2007
Posts: 303

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.


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 45
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

Joined: Jan 10, 2002
Posts: 56150
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

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

Joined: May 14, 2012
Posts: 45
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

Joined: Jan 10, 2002
Posts: 56150
    
  13

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

Joined: May 14, 2012
Posts: 45
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

Joined: Jan 10, 2002
Posts: 56150
    
  13

"Better" is always subjective and impossible to say without knowing a lot more.

I do either, depending upon circumstances.
Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 45
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JSP as a blueprint for several webpages
 
Similar Threads
Java cookbook
Some Rookie Testing Questions
Need info on how to design
favorite omelette?
Java Programming Cookbook