Forums Register Login

Create dynamically Html Page using Jsp and Java

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
 

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 .
1
+Pie Number of slices to send: Send
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
(1 cow)
+Pie Number of slices to send: Send
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.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1157 times.
Similar Threads
When to use a JSP page?
how to access data from the elements added via javascript dynamically using the jsp code.
Sending checkbox value to two different servlet page
Sending email
how to call a java file from jsp page?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 01:59:31.