File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically rendering JSP page

 
sreekanth jella
Greenhorn
Posts: 10
Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,

I have to render a JSP page based on a database table.

For example, there are two tables, one is having 2 columns and another is having 3 columns.

I will give one of the table name as input, based on this it should be able to render the next page. For the moment we can think all columns are having varchar2 datatype, so all fields should be rendered as text boxes.

Can you please suggest how to write JSP code for above requirement?
 
ujjwal soni
Ranch Hand
Posts: 403
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Are you using servlet or any java based MVC framework for this application ?? Or directly rendering it on jsp via scriptlets ?

Kindly clarify please.

 
Abhishek Asthana
Ranch Hand
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is a servlet, do the redirect conditionally.
 
sreekanth jella
Greenhorn
Posts: 10
Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ujwal,

I have to use either Struts 2 or Spring framework. Currently I am trying with Struts 2.

and also I have tried this using scriptlets. Here is my sample code.


But this is not recommended, I want to use some helper class to retrieve the meta data from DB table, and pass this information to JSP. But I didnt see any way to do in struts 2.

Let me know if any other information is required.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts 2 exposes data to JSPs through public getter methods: if you have a list (for example) of results of a DB query:

Then in the JSP:

Since you appear to be using scriptlets (almost always a Bad Idea) you could just put the list into request scope by either (a) implementing RequestAware (recommended) or (b) using the ServletActionContext utility class (not as testable).
 
sreekanth jella
Greenhorn
Posts: 10
Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David, It helped me.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic