If you put a parameter in request using request.setAttribute(), you have to retrieve
it using request.getAttribute() [and not request.getParameter()].
Hooke Kevin wrote:
> Hi - I am trying to call a servlet from a jsp page to perfrom a simple
> server-side include.
>
> I can successfully call the servlet, but any parameters I pass do not seem to
> make it into the servlet.
>
> I would like to use the following:
>
> <jsp:include page="/servlet/UIService?request_type=blank_dropdown"
> flush="true"/>
>
> This successfully calls the servlet, but the parameter passed in the url to the
> servlet are 'lost'... ie they don't seem to get passed into the servlet - if I
> try to do a request.getParameter("request_type"), it returns null.
>
> (If I call the servlet directly via a URL in my browser it works ok)
>
> I have also tried using the RequestDispather form my jsp code to do the same:
>
> <%
> RequestDispatcher dispatcher =
> application.getRequestDispatcher("/servlet/UIService");
>
> request.setAttribute("request_type", "blank_dropdown");
>
> dispatcher.include(request, response);
> %>
>
> - but the same happens here too.
>
> Heres the body of my servlet:
>
> import java.util.*;
> import java.io.*;
>
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class UIService extends HttpServlet
> {
>
> public void init(ServletConfig cfg)
> throws ServletException
> {
> }//end init()
>
> public void doGet(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException
> {
>
> String sRequest = req.getParameter("request_type");
>
> //output test back to client
> res.setContentType("text/html");
> PrintWriter out = res.getWriter();
>
> try
> {
> out.println("<!--generated output from servlet-->");
> if(sRequest != null)
> {
> if(sRequest.equals("blank_dropdown"))
> {
> out.println("<select><option></option></select>");
> }
>
> if(sRequest.equals("dummy_asset_dropdown"))
> {
> out.println("<select><option>Asset type 1</option>");
> out.println("<option>Asset type 2</option></select>");
> }
>
> if(sRequest.equals("get_dropdown_data"))
> {
> //testing only
> out.println("<!-- request_type: get_dropdown_data
> -->");
>
> //call db_servlet
>
> //return to calling jsp page
> }
>
> out.println("<!--end generated output from servlet-->");
>
> out.flush();
>
> //out.close();
> }//end if
> else
> {
> out.println("<!-- request_type is null -->");
> }
> }//end try
> catch(Exception e)
> {
> out.println("<hr></hr><h3>Exception caught in servlet:
> Transform</h3>"
> + "<p>" + e.getMessage() + "</p>");
> }
>
> }//end doGet()
>
> }//end Class UIService
>
> Anyone have any ideas?
>
> I am assuming that it is possible to be able to pass in parameters from jsp to a
> servlet like this...?
>
> Thanks in advance, Kevin Hooke
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html