• Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher  RSS feed

 
Shuaib Gill
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to pass a response to a JSP from a servlet using RequestDispatcher using jsdk 2.1, but it gives me an error...
WhichMarket.java:94: Method getRequestDispatcher(java.lang.String) not found in
interface javax.servlet.http.HttpServletRequest.
RequestDispatcher descriptionsRd=req.getRequestD
ispatcher(language);

^
1 error
Why is it giving this error and what can I do to pass the response to a JSP from a servlet. In a servlet I will use RequestDispatcher methodds to pass the response to the client. Why the error? Can someone tell me where I can find servlet docs 2.1?
Thanks.
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
R u callin the super(config) in the init method of the Servlet
Siva
 
Shuaib Gill
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I am using it in the request dispatcher itself. Here is my servlet. It does not forward to the color.jsp page. I am using ServletExec as my web server.
package com.company.dept.translation;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import javax.servlet.ServletContext;
import com.company.dept.translation.NotesBean;

public class WhichMarket extends HttpServlet
{
NotesBean notesData = null;
public void init() throws ServletException
{
notesData = new NotesBean();
getServletContext().setAttribute("notesData",notesData);
//req.setAttribute("notesData",notesData);
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
String usaCodeguide=null;
String canCodeguide=null;
String mexCodeguide=null;
String userInput = req.getParameter("market");
//String codeguideDescriptions="/servlets/descriptions.jsp";
// "/servlets/language.jsp";
try
{
if(userInput.equals("usa"))
{
int k=1;
//String usaCodeguide = null;
usaCodeguide = "450011";
//notesData.setSession(session);
notesData.setCodeguide(k,usaCodeguide);
//out.println(notesData.getCodeguide(k));
//out.println("usa codeguide");
}
else if(userInput.equals("canada"))
{
//RequestDispatcher anCG);
//canRd.forward(req,res);
int n=1;
//out.println("hello");
//String canCodeguide = null;
canCodeguide = "550012";
//notesData.setSession(session);
notesData.setCodeguide(n,canCodeguide);
//out.println(notesData.getCodeguide(n));
}
else
{
int j=1;
mexCodeguide = "27";
//notesData.setSession(session);
notesData.setCodeguide(j,mexCodeguide);
//out.println(notesData.getCodeguide(j));
//out.println("yo hey");
}
//RequestDispatcher nguage);
//descriptionsRd.forward(req,res);
RequestDispatcher forwardToLanguage = null;
//forwardToLanguage = forwardToLanguage = this.getServletContext().getRequestDispatcher("http://servername ort/xxx/yyy/zzz/color.jsp");
forwardToLanguage.forward(req,res);
//forwardToLanguage.include(req,res);
//out.println("hello there");
}
catch(Exception e)
{
out.println("Error: " + e.getMessage());
}
}// end doGet
}// end WhichMarket
 
Vedprakash Pathak
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check to see if you have two jar files containg javax.servlet.http.* package. This could be because of ambigous package name. Old javax.servlet package dowsnt have getRequestDispatcher(...) in HttpServletContext.
 
saurabh pathak
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi shuiab
I have seen ur code in jsdk2.1 their is no method defined getRequestDispatcher() in httpRequest but to use request dispatcher u simply use servlet context 's object for requestdispatcher as
RequestDispatcher rd=getServletContext().getRequestDispatcher("/yourjsp.jsp");
rd.forward(req,res);

In my opinion this willl works or u use servlet2.2 api for that u have to use java webserver or tomcat.

thanks
saurabh
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!