File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Exception: java.lang.StackOverflowError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception: java.lang.StackOverflowError" Watch "Exception: java.lang.StackOverflowError" New topic
Author

Exception: java.lang.StackOverflowError

k mut
Greenhorn

Joined: Aug 26, 2005
Posts: 16
the java program - CoverageArea.java

public class CoverageArea extends HttpServlet{


public void init(ServletConfig cofig) throws ServletException
{
System.out.println("the servlet started ");
}

public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, java.io.IOException
{

try{
System.out.println("1************u have entered the action of coverage area");
System.out.println("222221************u have entered the action of coverage area");
RequestDispatcher view = request.getRequestDispatcher("test.jsp");
view.forward(request,response);
}
catch ( StackOverflowError e ) {
System.err.println("Exception: " + e );
// Here is the important thing to do
// when catching StackOverflowError's:
e.printStackTrace();
// do some cleanup and destroy the thread or unravel if possible.
}


}

}




web.xml i have the following code

<servlet>
<servlet-name>coveragearea</servlet-name>
<servlet-class>com.nbd.nbdpublicsite.CoverageArea</servlet-class>
</servlet>



<servlet-mapping>
<servlet-name>coveragearea</servlet-name>
<url-pattern>/pages/test.jsp</url-pattern>
</servlet-mapping>



when i call call test.jsp the servlet starts but runs in loop and throws
Exception: java.lang.StackOverflowError
java.lang.StackOverflowError


actually when i type in test.jsp in address bar the servlet needs to pull datas from database i.e. coverageareas and it should be displayed in the same jsp.
how can i work on this.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why don't give the mapping a url-pattern other than the name of the JSP that you're using for the view?
What you're doing is putting you into a recursive situation.
Like a snake eating it's own tail.

If you want to prevent direct JSP access, put the JSPs under the WEB-INF directory.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
k mut
Greenhorn

Joined: Aug 26, 2005
Posts: 16
how will i get the test.jsp in the explorer as i am using the jsp before and after servlet call
k mut
Greenhorn

Joined: Aug 26, 2005
Posts: 16
i get The requested resource (/WebRoot/WEB-INF/test.jsp) is not available.
when i access test.jsp
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Generally, in an MVC setting, you would hit the Servlet, where some processing gets done (maybe by intsanciating some beans and calling their methods), and then forward to the JSP for display.

You say you're hitting the JSP first.
Why?

It almost sounds like your using the servlet as an include.
I'm not sure why you would want to do this.
Can you elaborate?
[ November 15, 2005: Message edited by: Ben Souther ]
k mut
Greenhorn

Joined: Aug 26, 2005
Posts: 16
actually we gave the link to our important customer as
http://www.yourcompany.com/newpublicsite/pages/coverageareas.jsp
they have this link in thier application to get information from our webpage
and they do something for their customer.
so we don't want to change this path.
now here it is a static page
now this need to be dynamic so when ever we update the database this page when ever customer accessses this page they will get updated information.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The servlet mappings in web.xml give you all kinds of flexibility.

I would build the dynamic version with a different JSP using a proper MVC pattern. Once it is working properly, I would change the url-pattern in the mapping so that the the link they have currently will point to your servlet. Then, dump the current JSP.

The key is to make sure that the servlet isn't forwarding to itself.
Otherwise your app will recurse like a dog chasing it's tail.
k mut
Greenhorn

Joined: Aug 26, 2005
Posts: 16
thanks
I created the jsp under WeB-INF it worked very well.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception: java.lang.StackOverflowError