This week's giveaway is in the Java/Jakarta EE forum. We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line! See I am Attaching my servlet code as well as xml code.
tarunv Verma wrote:I required onload = submit because i have to show some dynamic images when the page opens.
That makes no sense to me at all. I agree with Jk -- you're doing it wrong.
Why not back up and instead of getting us to try and help you do it wrong, describe what you are actually trying to accomplish so we can help you do it right.
May be i am doing it in a wrong way. I will explain you my problem. Please have a look at it.
I have some text file which keep on changing after 5 mins. On basis on those files i have to make dynamic image for each file. When the user open the page he should see all the images without clicking anywhere but when he clicks on the image a log file should be available for downloading. I hope that has given you a good idea about my problem.
Jk Robbins wrote:Ok, let me see if I understand. I'm thinking something like this:
Send a request to a servlet which will determine which images to display.
Put the image file names into a collection and send it to a jsp to display the images as links.
Now you can either use the links to take you to the log page, or initiate a download, or you can use Ajax to capture the click event on any image and use that to fetch the log.
I hope I'm understanding the requirements correctly.
Thats what i want to know how to request servlet without window=onload. I was using .net technology before in that there is a function page_load() in which we can apply what we want at loading of page. So i am looking similar kind of thing. Hope to see your reply on that.
That will send a GET request to the servlet. You can include parameters if needed using init-params in the web.xml or in the URL using the "?key=value&" format. Now the servlet can build the response and send it whatever page you designate with the RequestDispatcher.
I think your mistake is thinking that you need to call a page first and then let that page call the servlet. It doesn't need to be done that way, and in fact, shouldn't be done that way.
"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
tarunv Verma wrote:Thats what i want to know how to request servlet without window=onload. I was using .net technology before in that there is a function page_load() in which we can apply what we want at loading of page. So i am looking similar kind of thing. Hope to see your reply on that.
That might have been the way to work with .Net, but it is not the way to work with Java web apps. You're just going to create a big old mess.
Pay attention to what you've been told here and in the linked articles.
You do not hit the JSP first. You hit a servlet first.