This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am trying to call a servlet with parameter "item" and include the output to my outputstream.
res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("hello"); RequestDispatcher rd = getServletContext().getRequestDispatcher("/servlets/xxxServlet?&item=xxx"); rd.include(req, res); In the xxxServlet, Iam getting the parameter value for "item" using request.getParameter and printing it out as below:
PrintWriter out = res.getWriter(); out.println("item = "+request.getParameter("item")); But I get the following output: hello
but not the output from the xxxServlet. If I don't give any parameter, then I get the following output: hello item=null How can I get the proper output "hello item=xxx" ? thanks.
Hi - I tried it with and without the &. I always get item=xxx. I get item=null only if I do not code the item parameter at all. I think it is a problem with the container's aggregation of parameters. ??? What container are you running? Regards, Guy [ March 08, 2002: Message edited by: Guy Allard ]
I tried this one myself. It appears that ampersand does not have any effect. I am always getting the correct parameter also. Only time I am not getting anything from the included servlet is when my path to the included servlet is not right. But since, you are getting item=null, this wouldn't apply. Also check to see if you have to manually restart the server (In case you do not have auto-reload feature) to see the changes
With RequestDispatcher you can forward/include the request. But it should always be done before any response committment to the browser. So if you are using out.println("hello"); before RequestDispatcher it will give exceptions and won't work properly. Try removing out.println("hello");