aspose file tools*
The moose likes JSP and the fly likes Need to show dynamic field in JSP (read from xml file) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Need to show dynamic field in JSP (read from xml file)" Watch "Need to show dynamic field in JSP (read from xml file)" New topic
Author

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

vidhi raman
Greenhorn

Joined: Aug 22, 2013
Posts: 2
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

Joined: Sep 13, 2007
Posts: 2597
    
    9

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
vidhi raman
Greenhorn

Joined: Aug 22, 2013
Posts: 2
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

Joined: Sep 13, 2007
Posts: 2597
    
    9

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

Joined: Aug 25, 2013
Posts: 14
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 :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to show dynamic field in JSP (read from xml file)