Passing parameters between JSP and Servlet

The scenario is as follows:
There is a JSP page that sends a string as a hidden parameter to a servlet:
<input type="hidden" name=<%= Book.NAME %> value=<%= book.getName() %> >
In the servlet there is a print statement that checks the parameter value:
System.out.println("Book name: "+request.getParameter(Book.NAME));
The problem is as follows: if the name of the book consists of more than one word
such as "Servlets and JSP", the print statement will print only Servlet.
If the JSP page passes a string directly as shown here:
<input type="hidden" name="Test" value="Test String" >
The servlet will print the complete string: Test String
The same problem appears if the string is passed between two JSP pages.
Any help is greatly appreciated.
Regards,
Basil Mahdi

You might want to try
<input type="hidden" name="<%= Book.NAME %>" value="<%=URLEncode.encode(book.getName(), "UTF-8")%>" >This will take care of any wierd un-url friendly charcters that might appear in the book titles such as the ' or " which may be the problem.

Similar Messages

  • Urgent! pass parameters between jsp pages

    Does anyone can give an example about how to pass parameters between jsp pages?
    This is what I do:
    pageContext.forward("pag_loginc.jsp?p_idusr=" + strUsr + "&c_password=");
    But when deployed is not working.
    Help is needed.

    can you put that stuff in the session context in the first page, then pull it out in the second page?

  • Passing values between jsp and php

    hi there, is it possible to pass values between jsp and
    php? i really need to find out the way if there is
    any. thanks in advance
    -azali-

    Yes, there are a few ways to do this.
    1) Think about using Cookies.
    2) Maybe use a Redirect passing the values in the Query string.
    3) Retain the data in a repository in the back end.
    4) Using Hidden fields within your pages.
    I am sure you can use these Idea's for a base to develop other methods on how to pass values back and forth from JSP -> PHP and vice versa.
    -Richard Burton

  • How to pass parameters between main and sub vi during parallel execution using the VI server technique?

    Hello All,
    I am working with the following example (from previous postings on this
    board) that demonstrates how to run a sub vi in parallel with the main
    vi.  I'd like to pass parameters between the main and sub such as
    the control (delay) and indicator (value) parameters of my subvi
    example.  Does any one know how to do this?  Parallel
    execution is important for me, I cannot just paste the subvi icon into
    my main diagram (two nested while loops...)
    Many thanks,
    Luis
    Message Edited by cascao on 08-16-2005 08:42 PM
    Message Edited by cascao on 08-16-2005 08:42 PM
    Attachments:
    VI_Server_technique.vi ‏32 KB
    SubVI_1.vi ‏19 KB

    cascao wrote:
    Hello All,
    I am working with the following example (from previous postings on this
    board) that demonstrates how to run a sub vi in parallel with the main
    vi.  I'd like to pass parameters between the main and sub such as
    the control (delay) and indicator (value) parameters of my subvi
    example.  Does any one know how to do this?  Parallel
    execution is important for me, I cannot just paste the subvi icon into
    my main diagram (two nested while loops...)
    Many thanks,
    Luis
    Luis, you can use the VI Server methods 'Set Control Value' and 'Get Control Value', as demonstrated in the attached examples.
    -Franz
    Attachments:
    VI Server.zip ‏26 KB

  • Difference between jsp and servlets

    Can any body tell me the difference b/w jsp and servlets.
    As i know one difference is to seperate the java code from html. Is there any other difference. please...

    Servlets are a way to run java on a server. They don't necessarily need to be about HTML or even HTTP. You can write servlets that generate images rather than HTML, for example.
    JSP is a way to create servlets that generate HTML. They get translated into servlets (special-purpose servlets). This is sort of glossing over the details -- the power of JSP is that, by being an intersection between HTML and executed Java code, they can provide a way to clearly differentiate between the two.
    That's a way of looking at it anyway.

  • What is the diff between jsp and servlet

    is thr any other difference betwwen jsp and servlet, tht: jsp is automatic generated servlet and jsp has different types of tag, due this we have write less amount of code.any other technically difference between these two?

    As you mentioned JSP automatically gets converted into a Servlet and then compiled. From the server's perspective other than the transformation process, there is no real difference.
    However, in coding there are some minor differences such as additional access to pre-defined variables and different syntax for some minor things such as imports and etc.
    Perhaps somebody else more knowledgeable can fill you in further.
    Hope that was helpful.

  • Urgent: problem with sharing HttpSession  object between Jsp and servlets.

    Hi,
              We are using weblogic 6.0 sp2.
              I m setting a particular object in session in a servlet using
              session.setAttribute() but when i try to retrieve that object using
              session.getAttribute() in a jsp page the value of that object is null. Is
              there any way to configure HttpSession in weblogic so that jsps and servlet
              can share the same session? Or any workaround for this problem.
              Any help in this regard is appreciated.
              Thanks
              -Shree
              

    Just a guess, but it sounds like you have cookies turned off and are not
              using encodeURL. Try enabling cookies and see if that solves the problem.
              Also, it is generally good practice to use encodeURL to protect yourself
              from users who disable session cookies.
              Here's how we use encodeURL in our Servlets:
              gotoPage("/jsp/someJSP.jsp");
              private void gotoPage( String address,
              HttpServletRequest request,
              HttpServletResponse response )
              throws ServletException, IOException
              RequestDispatcher dispatcher =
              etServletContext().getRequestDispatcher( response.encodeURL( address ));
              dispatcher.forward( request, response );
              "Shree Unde" <[email protected]> wrote in message
              news:[email protected]..
              > Hi,
              > We are using weblogic 6.0 sp2.
              > I m setting a particular object in session in a servlet using
              > session.setAttribute() but when i try to retrieve that object using
              > session.getAttribute() in a jsp page the value of that object is null. Is
              > there any way to configure HttpSession in weblogic so that jsps and
              servlet
              > can share the same session? Or any workaround for this problem.
              > Any help in this regard is appreciated.
              > Thanks
              > -Shree
              >
              >
              

  • Choice between JSP and Servlet

    I am new to JSP and Servlet. I know JSP container will convert JSP to servlet
    eventually. But in application development's standpoint, anything can be
    done in servlet can also be done in JSP? Some people told me we can
    use the combination of both in one application.
    My question is in what situation we use JSP alone, servlet alone, or
    combination of both??
    Please advise. Thanks!!

    Use a combination of both.
    Your Web application should have a single servlet that all HTTP requests are POSTed to. All the servlet does is act like a traffic cop: it figures out what the request is, delegates to other objects that do the work, and forward the result to the next JSP, whatever that is. It's called a front controller servlet.
    The JSPs should just be pure dynamic presentation. Everything displayed in the pages should have been generated by the servlet and its helper classes. No database queries, etc. Your JSPs will be a lot better off if you learn JSTL and eliminate all scriptlet code.
    Check out frameworks like Struts.

  • Passing session data between jsp and servlet

    I have a servlet that I pass data to my jsp.
    I do a session.setAtrribute in the servlet. No problem.
    I get the data no problem in the jsp that I call.
    How do I pass this same data to the another servlet?
    I basically have an array of values that I already have in the existing jsp that has been set in session.
    When I call the secondary servlet, I don't have anything in this session variable related to my array.
    Prior to posting to my next servlet, do I need to do another setAttribute inside the jsp to get the data passed to the servlet?
    Thanks.

    Two different things. The encoding adds this to the URL (after the page, before the query string
    ;jsessionid=ABC123 but only if the user isn't using cookies.
    So in your example, you would do this (maybe):
    <%
      String url = response.encodeURL("Servlet");
    %>
      <form name="form1" method="post" action="<%= url %>?cmd=pay"> ... Or some modification.
    So the difference between encodeing and using a post is that
    1) encoding adds the jsessionid to the url string if necessary. It does nothing else
    2) POSTing will send a request to the provided URL via the POST method, including the inputs of the form as parameters to the URL.
    They really don't interact with each other. It is like asking what is the difference between the Color Orange and thr Size Big? They can both be applied to the same thing, or not... and have no real relation to each other.

  • Passing parameters between WDA and Iview URL.

    Hi,
    I've a Iview type URL and I want to passing parameters through of code of my WDA. I Know to call a Iview for code  but I don't know passing parameters. I used this method for call the iview:
    CALL METHOD l_portal_manager->navigate_absolute
    EXPORTING
    navigation_target = path
    navigation_mode = if_wd_portal_integration=>co_show_external.
    (path = roles//....idiview).
    Thanks.

    Look at this thread..
    Re: Get URL Parameter Starting With underscore '_' (_sapwiid)
    <i>*Reward each useful answer</i>
    Raja T

  • URL mapping  between jsp and servlet

    recently, I try glassfish, and I get surprised, for example My application name is HelloWorld if I have jsp action to servlet I can't use action ="servlet/myservlet1" I have to use
    action="HelloWorld/myservlet " if I put my servlet2 under test folder I can't call this servlet by servlet/test.servlet2, I have to use HelloWorld/servlet2,. I realize that is not glassfish problem , I just wonder is any one could give more expiration on servlet mapping ??
    Thank you !

    Depends on several factors. In which context and how exactly are you specifying the URL? In client context, the leading "/" brings you to domain root. In servlet context, the leading "/" brings you to context root. The HTML <a> element is relative to client context and JSTL <c:url> is relative to servlet context. That kind of things.

  • Passing values between ajax and servlet

    Hi,
    This is taking me nowhere and i'd wish someone could point out my mistakes.
    Here are the files i've created,
    MyForm.jsp: contains a dropdownlist and a text input, and AJAX function to call MyServlet
    MyServlet servlet: access db to retrieve data to fill up MyForm text input
    Required action+ User selects an option from dropdownlist to fill up textfield
    Expected result+ textfield displays "my result"
    Actual result+ textfield displays "my result<space><space>" (with extra two blank spaces!!!)
    No matter how long the expected result is, it'd append 2 blank spaces at the rear of xmlHttp.responseText.
    I'm having the following codes in AJAX,
         var url="/MyApp/servlet/MyServlet";
         url=url +"?param="+ document.form1.menu.value;
         xmlHttp.onreadystatechange=stateChanged;
         xmlHttp.open("POST",url,true);
         xmlHttp.send(null);
    }and return the result from servlet as follows
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws Exception {
         //select record from db based on param, and
         //save as myresult
         out.println(myresult);
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws Exception{
         doGet(req,res);
    }Any idea?
    /z

    alright, guys. i spotted my mistake. jesus, how could i overlooked it!
    just replace out.println with out.print()
    i didn't realize the carriage return.

  • Passing Parameters between Portal and Forms 6i

    Hi,I'm new in Oracle Portal and I have a problem. I have a Portal's report and I need to pass a value from this report to Form 6i to perform the query. This form is a porlet including in the Portal page.
    please help me

    Hi, Im trying to do that you said, but doesn't work :-(, my code is something like this, in the portlet.xml(jboss portal 2.6) :
    <portlet-preferences>
    <preference>
    <name>stockSymbols</name>
    <value>BEAS</value>
    </preference>
    <preference>
    <name>refreshInterval</name>
    <value>600</value>
    </preference>
    </portlet-preferences>
    in the consumer(bea wlp 8.1 sp5), i dont see any portlet preference in the palette window, im doing something wrong?...thanks for your help.

  • Passing parameters between server and client side

    Dear All
    I writing a server-side web service and using wsdl to expose its methods for a 'client' to use.
    However, i need to make sre the clients creates a soap header? How can i tell the client it must create a soap header?
    Also can someone tel me how i pass a value from the server-side to the client-side and also get a vlue from the client soap message
    Many thanks

    In your wsdl you would have the header as part of the input for example, see the operation below:
    <wsdl:operation name="foo">
    <soap:operation soapAction="http://www.foobar.com/foo" style="document"/>
      <wsdl:input>
       <soap:body use="literal"/>
       <soap:header message="tns:FooSoapHeader" part="MySoapHeader" use="literal"/>
      </wsdl:input>
      <wsdl:output>
       <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>

  • Passing values between JSP and Bean

    I am trying to validate a date entered by the user on a form. I need to do an "alert" when the user enters a date outside of the valid range depending on a value entered in a drop down.
    Am doing this in checkform function. Here is what I want to do:
    1. Send the the value from the drop down and the date to bean to do the calculations. Call the EJB function from checkform.
    2. Get a string values back into the jsp from the bean
    3. Blow an error to the user to enter a valid date.
    Any help in this case would be greatly appreciated.
    Thanks.

    I only see some design requirements.
    What's the exact coding question? Where are you stucking while coding those requirements accordingly?

Maybe you are looking for

  • HP Touchpad Issues - HP ENVY 15t-q100 - Needs Reflashed to Function Properly -

    I have the HP Slim Quad 100 Notebook with the HP Synaptics Touchpad. The touchpad intermittently stops working correctly.  Sometimes it's so bad that it's unusable.  I have done a little research and I found that the driver is causing the Touchpad to

  • GPS nokia 5800 Xpressmusic

    Hi, I'm from Romania and I want to use GPS for free but i can't.I don't lnow how work.Where is the download for Gps for my Nokia,how to install?Thanks! I have already installed Maps but don't work,i can't see the maps.

  • Table fields for Status of an equipment.

    Hi Experts, Can anyone tell me Tables and fields available for Status of an equipment. Which is shown in IE03. i.e. 'INST','AVLB'......etc. Thanks, Ashesh Chokhawala.

  • Word and excel

    I have been told that my 2004 version word and excel are not supported on my Lion. Is there a new version that is ?

  • Error in KM search iView

    Hi All,   I have created a new KM Search iView.   I saw the iView's preview and entered a document's name (giving the folder's name: /documents/myFolder).. but, i got the following error: <b>AbstractTrexIndex.getLanguagesOfIndexedDocuments: Index doe