• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RequestDispatcher

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
What are you doing? You are supposed to be reading this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic