• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to show dynamic field in JSP (read from xml file)

 
vidhi raman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need to make a jsp page which contain no of control dymanic, I mean I have one xml file and based on this file I need to generate jsp at run time.

Can any one please suggest me how we can do it.

 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You mentioned reading from XML. Have you parse the XML file? How is the content/data from the xml file map to the JSP field?

You should use those XML api to parse the xml file.
 
vidhi raman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes I am using xml API to parse it but how to generate jsp file at run time, moreover how it will be compile.
 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vidhi raman wrote:Hi,

Yes I am using xml API to parse it but how to generate jsp file at run time, moreover how it will be compile.


Don't know how your page will look like. Is it a form or pure data? If pure data, you can create a jsp as usual. Just in your servlet, where you do your xml stuff, forward to your jsp page.

Suppose I want to list out the projects I have done. This data is in xml file. So I have a "Project" POJO. I have a ParseProject servlet that reads the xml then forward to a project.jsp and display.




Then in JSP with the help of JSTL
 
Frederik Nielsen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are looking for a Servlet Filter class.

It looks like this:



Then in your web.xml you have this code:



Now every single request on your site will first have to go through the filter. What what? can it be that simple? YES :)
Now in your filter you just have to read through the XML file and then pass it in a session or just the request to the JSP that can then display it

This also ensures that the user wont be able to get to the JSP if there is an error in your XML file which could lead to a complete crash of the page.

I use a filter to get all the data for all my JSP pages and also creating sessions and objects needed for the JSP pages.
Then the JSP pages ONLY job is to display data :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic