This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes page is not shown only url is showing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "page is not shown only url is showing" Watch "page is not shown only url is showing" New topic
Author

page is not shown only url is showing

tarunv Verma
Greenhorn

Joined: Dec 14, 2011
Posts: 16
hello everyone i have to show a page index.jsp and in this page i have used the onload submit


the above is my jsp code and i have printed hello on this page. But when i hit the URL localhost:8090/tempmonitoringsystem/index.jsp.
It shows index.jsp for nanosec den went away to the folowing URL localhost:8090/tempmonitoringsystem/tempmonitor and i don't know where it is redirecting to.
I am Attaching my servlet code as well as xml code.

TempMonitorServlet.java


web.xml



Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

System.out.println("hello world"); are you getting this output on server console? any error on server log(console)?
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 853
    
  13

The onload event is submitting your form the same as if you had clicked a submit button. This performs a POST which will clear the page.

In addition, you are doing things backwards. The browser should be calling the servlet which will put your data into a request (or other scope) and then forward to the jsp page.


"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
Greenhorn

Joined: Dec 14, 2011
Posts: 16
Seetharaman Venkatasamy wrote:System.out.println("hello world"); are you getting this output on server console? any error on server log(console)?


No no error is coming infact every computation is going smooth. But at last index.jsp shows for a while and went off to the URL as i have mentioned.
tarunv Verma
Greenhorn

Joined: Dec 14, 2011
Posts: 16
Jk Robbins wrote:The onload event is submitting your form the same as if you had clicked a submit button. This performs a POST which will clear the page.

In addition, you are doing things backwards. The browser should be calling the servlet which will put your data into a request (or other scope) and then forward to the jsp page.



I understand what you are saying but how to overcome from this problem. I required onload = submit because i have to show some dynamic images when the page opens.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
tarunv Verma
Greenhorn

Joined: Dec 14, 2011
Posts: 16
Bear Bibeault wrote:
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

tarunv Verma wrote:On basis on those files i have to make dynamic image for each file.

How?
When the user open the page he should see all the images without clicking anywhere

So why cannot you just use an image tag?
but when he clicks on the image a log file should be available for downloading.

Sounds like a simple link.
tarunv Verma
Greenhorn

Joined: Dec 14, 2011
Posts: 16
Bear Bibeault wrote:
tarunv Verma wrote:On basis on those files i have to make dynamic image for each file.

How?
When the user open the page he should see all the images without clicking anywhere

So why cannot you just use an image tag?
but when he clicks on the image a log file should be available for downloading.

Sounds like a simple link.


But i have to run the servlet to run the logic, to pick the data from the files to make it available for images.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 853
    
  13

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Jk's approach sounds about right to me.

You might also read this article on best-practice web application structure.
tarunv Verma
Greenhorn

Joined: Dec 14, 2011
Posts: 16
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.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 853
    
  13

You just point your browser (URL) to the servlet mapping. Let's say you have a servlet named and mapped like so:



The URL you want would be http://mycontext/CuringClock

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.

Incidently, the page_load or on_load events are generally used for initiating Javascript, but we're not even going to get into that yet. Please read the link that Bear provided, I think you'll find it helpful along with several of the other faqs on this site. You seem to be struggling with some of the basics of web apps, but once you understand the basics of web app structure and the client to server communication, everything is going to fall into place for you.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

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.
 
jQuery in Action, 2nd edition
 
subject: page is not shown only url is showing
 
Similar Threads
Simple JPA application on TOMEE
Disable HTML frame using Javascript
Problem in I18N in Spring
PDF Download not working in Production.
text file extractor