aspose file tools*
The moose likes Servlets and the fly likes RequestDispatcher problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

RequestDispatcher problem

Chidanand Chauhan
Ranch Hand

Joined: Nov 10, 2005
Posts: 77
Hi
I have a problem with the request dispatcher. Can anybody solve my problem.

if i am using this command for forwarding the request and response to the jsp, i get ParseException problem.

RequestDispatcher disp;
disp = request.getRequestDispatcher("login.jsp");
disp.forward(request,response);

please tell me the above code is correct or not. since my servlet class file and jsp file stores in the same location. relative path is correct or not.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Chidanand Chauhan:
since my servlet class file and jsp file stores in the same location.


They shouldn't be in the same location.
Servlets should be under WEB-INF/classes/{your package name}/{servlet class files}.

How do you have your webapp laid out?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Chidanand Chauhan
Ranch Hand

Joined: Nov 10, 2005
Posts: 77
myServlet classfile is in
tomcat/webapps/myapplication/WEB-INF/classes/com/example/<Servletclassfile>

and jsp file is in
tomcat/webapps/myapplication/<jspfile>
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

The path name ought to begin with a slash ("/") representing the current context. So if your jsp is directly under the web root folder, then



should do the trick.

ram.
Chidanand Chauhan
Ranch Hand

Joined: Nov 10, 2005
Posts: 77
Originally posted by ramprasad madathil:
The path name ought to begin with a slash ("/") representing the current context. So if your jsp is directly under the web root folder, then



should do the trick.

ram.


No its still giving the error i am pasting my error here.



exception

org.apache.jasper.JasperException: /login.jsp(0,19) quote symbol expected
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:428)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:126)
at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:174)
at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:136)
at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:149)
at org.apache.jasper.compiler.ParserController.figureOutJspDocument(ParserController.java:254)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:173)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:153)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:227)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:369)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at com.example.GuestJsp.doGet(GuestJsp.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)



--------------------------------------------------------------------------------

Apache Tomcat/4.1.30



please tell me what to do i am sending my mail servlet code link..
Chidanand Chauhan
Ranch Hand

Joined: Nov 10, 2005
Posts: 77
Servlet code is

package com.example;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class GuestJsp extends HttpServlet {


public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{

req.setAttribute("message", "Hello, world");



RequestDispatcher disp;
disp = req.getRequestDispatcher("/login.jsp");

disp.forward(req, res);
}
}
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


org.apache.jasper.JasperException: /login.jsp(0,19) quote symbol expected
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)


[/bold]That's an error in your login.jsp [bold] and not in the request dispatcher per se.
However I noticed that you use the request object to get a RequestDispatcher. This is slightly tricky as it accepts relative paths as compared to the RequestDispatcher obtained through a context object.



Having said that, the use of "/" at the begining indicates the context root, so I guess its ok.

cheers,
ram.
Chidanand Chauhan
Ranch Hand

Joined: Nov 10, 2005
Posts: 77
But still its not working.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I think this thread is continued here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher problem
 
Similar Threads
Using RequestDispatcher with <c:url> tag
Servlet
Request Dispatcher
Problem with getRequestDispatcher
Call a servlet from another servlet