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

Very simple JSP with Scriplet

Raja Shekar
Greenhorn

Joined: May 20, 2008
Posts: 3
I have a very simple JPS with 4 lines of code. While launching the page am getting the below exception. Please help in resolve this
Server :Tomcat 6.0.16
OS: Windows Vista.
JDK :Java6

index.jsp
---------------
1 <%
2 response.sendRedirect("first.jsp");
3 return;
4 %>
-----------------

Exception:

May 21, 2008 12:21:41 AM org.apache.jasper.compiler.Compiler generateJava
FINE: Generated /C:/apache-tomcat-6.0.16/work/Catalina/localhost/weblog//org/apache/jsp\index_jsp.java total=19 ge
te=5
May 21, 2008 12:21:41 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 9 in the jsp file: /index.jsp
Unreachable code
6: <%
7: response.sendRedirect("first.jsp");
8: return;
9: %>
10: </body>
11: </html>


Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:316)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:129)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:61)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

JSPs get translated into servlets. You have an unconditional return in your JSP that is followed by something -- in this case HTML markup.

The servlet code that is generated to emit the HTML markup is after the return, and therefore is unreachable. This is not legal in Java.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Raja Shekar
Greenhorn

Joined: May 20, 2008
Posts: 3
Thanks that worked.
Sorry for confusing with huphens' (-----)
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Its always better to look at the generated servlet class in order to troubleshoot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Very simple JSP with Scriplet