• Post Reply Bookmark Topic Watch Topic
  • New Topic

Create dynamically Html Page using Jsp and Java  RSS feed

 
Nitish Govekar
Greenhorn
Posts: 25
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create html page dynamically everytime i click on Submit Button.
In my project i am using Jsp/Servlets .
And in that html file i want to fetch the data from another jsp page
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt that you need to create an entirely new HTML age at each request. What part of the new pages is different from the others. Just the displayed data, right? (Or is even some of that shared?)

So you need a shared JSP page or (small set of pages) that has all the common markup and the ability to show the different data.

Perhaps if you cows explains what you are trying to do, we'd be able to offer more details than that.

 
Nitish Govekar
Greenhorn
Posts: 25
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I doubt that you need to create an entirely new HTML age at each request. What part of the new pages is different from the others. Just the displayed data, right? (Or is even some of that shared?)

So you need a shared JSP page or (small set of pages) that has all the common markup and the ability to show the different data.

Perhaps if you cows explains what you are trying to do, we'd be able to offer more details than that.



What i am trying to do is get values from database for each result and store it on to new HTML page .

For every new user a new html file should get created .
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What Bear is trying to convey here, is the visual aspects of your rendered page most probably remain the same, only the values differ
e.g. Compare these two
https://coderanch.com/u/356245/Nitish-Govekar
https://coderanch.com/u/24697/Bear-Bibeault

As you can see the visual layout, placement etc is exactly the same. Only difference is the values, which is the data which came out of some DB.

To summarize, all your visual aspects (only) should be in the JSP and data values (from the DB) should be populated at runtime.
Check out this excellent article (incidentally by Bear himself) http://www.javaranch.com/journal/200603/Journal200603.jsp#a5
 
Matt Keller
Ranch Hand
Posts: 32
1
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are trying to use straight JSP to do the database call and everything.  That is the first generation of JSP coding and while it works just fine, your code will become very messy because you are putting all your java logic in your JSP.  A much better model is to only have the visual logic in the JSP.  This means you JSP looks like a bunch of HTML with a tag outputting a value from a bean anywhere in the page where you need some data to appear.  You also can put some simple if statements in the page and maybe some loops to render tables, but beyond that there is not much logic in your jsp page.  Originally people were also writing their own tag libraries.  Then JSTL came along and covers almost all of the basic stuff you want to do.  So, where does the rest of your logic reside you might wonder.  Well, its in servletts that "catch" the params and then lead to the jsp.  This is what frameworks like struts and spring are for.  So, I recommend not using straight JSP unless you have to.  Here is the basic life cycle for a struts or spring application.

1) params are submitted from browser to a URL on the server
2) params land in a bean matching the bean setter names
3) a controller method is executed which looks like plain old java, it has a handle to the bean and calls the getters to get info that came from the browser, it calls other methods and classes to go to the db, access services etc, and then puts information of its own into the bean, often if a different member variable than where the params landed, it then forwards to a jsp
4) jsp runs, uses values from the bean to render using tags, html is sent back to browser

It's actually not that complicated, and by separating the controller logic from the display logic you will make something that is maintainable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!