wood burning stoves 2.0*
The moose likes JSP and the fly likes IllegalStateException on page load    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 » JSP
Bookmark "IllegalStateException on page load    " Watch "IllegalStateException on page load    " New topic
Author

IllegalStateException on page load

John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
I have a simple index page the i am using as my application entry point. I need this page to call a servlet then return an array of brands to fill in on my home page. Now i alwyas get this error and sometimes the brands never fill in on the page. I have searched and tried different things o found on the web. In the html file i commented the different ways i have tried but still get the same result. Is there a better way to try to do what i am doing or do i just have a syntax error?

Thanks,
John

exception


index.jsp


Servlets






Edited by: jonnyd9191 on Oct 2, 2008 2:56 AM
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

You are trying to forward after you have emitted some output. No can do.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Originally posted by John Schretz:
I need this page to call a servlet then return an array of brands to fill in on my home page.

You're doing it backwards. Servlets should call JSPs, not the other way around.

Please see this article for information on accepted best practice web application constructs.
[ October 01, 2008: Message edited by: Bear Bibeault ]
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
yes, but this jsp page is my entry point. so when i go to www.mypage.com this is the first page called. I then am calling the servlet so i can load my home.jsp page with the proper information. Is there a way that when i go to www.mypage.com the first thing executed is the servlet?

thanks
john
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

YOu can set any resource to be the welcome file. Please read up on this concept in the deployment descriptor.
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
yes, i have tried that before.
In my web xml, i did servlet mapping
Then in the welcome file tags i entered the mapped servlet.
This did not work.

<welcome-file>
//mapped servlet here
</welcome-file>
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Two redirects in the JSP and one in the servlet

I think you should rework your design, take a good look at the link provided by Bear above, reduce the coupling or the code above will be a maintenance nightmare in near future.

Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalStateException on page load
 
Similar Threads
Calling servlet on page load
problem calling servlet to build a list of data from a database and display a jsp page
JSP Not Reading Arraylist
exception while running code
Problems with paging i created