How to exchange information(parameters) between servlets & jsps

with an examle if possible.

Hi
Exchanging parameters/objects between JSP and Servlets is done by creating an Object and placing it in the ServletContext , User Session or the Request depending on whether the Object requires Application Wide scope, Session Scope or Request Scope respectively.
If the object is created in the Servlet then it can shared by placing it in either Context, Session or Request through the setAttribute method and similarly retrieved through the getAttribute method.
For JSP use the <jsp:useBean> tag to retrieve/create the Object (bean).
For eaxmples see the following Links:
http://java.sun.com/docs/books/tutorial/servlets/communication/attributes.html
http://developer.java.sun.com/developer/onlineTraining/JSPIntro/contents.html#JSPIntro11
Good Luck!
Eshwar Rao
Developer Technical Support
Sun microsystems
http://www.sun.com/developers/support

Similar Messages

  • Crypt & decrypt parameters between servlets

    Hi,
    I am developing a web application and I would like to know how to crypt the parameters
    I send through a get or post method to another servlet. For example if I send a keyid from
    a url, you can see the keyid in the url. I want to crypt it in order that they will see something
    like JD()$(/$#"#1332 instead of the keyid.
    Thanks in advance

    First, POST is not a solution. Just because its not in the URL doesn't mean a user can't get at them. If it was just cosmetic (he wanted a clean URL) then POST would be okay. He wants things encrypted, so I assume that he doesn't want people to know what the values are.
    There are a couple of possible solutions. One requires server side storage overhead.
    1) Map the actual values to dummy values before you write the page. Create a HashMap, store the key id in the HashMap with a randomly generated key. Use the randomly generated key in the URL.
    String keyid = "realkeyid";
    HashMap map = new HashMap();
    String randkey = Integer.toString(Random.nextInt());
    map.add(randkey, keyid);
    session.setAttribute("map", map);
    //--- Now use the randkey value on your web page URL
    When the next request comes in, take the key in the URL, get the HashMap from the session and use the key to get the real keyid.
    2) Use a cipher to encrypt strings before writing them to the page. Store the crypt key in the session. Change the crypt key with each request or login or whatever.
    String keyid = "realkeyid";
    long cryptKey = System.currentTimeMillis();
    String cryptedKey = MyCipher.encrypt(keyid, cryptKey);
    session.setAttribute("cryptkey", new Long(cryptKey));
    //--- now use cryptedKey on the page or URL
    When the next request comes in get the key from the session and decrypt the key.
    long cryptKey = Long.longValue((Long) session.getAttribute("cryptkey"));
    String keyid = MyCipher.decrypt(request.getParameter("keyid"), cryptKey);
    //--- now keyid should contain the real keyid
    Considerations:
    Option 1 will not work for large data sets. You would have to store too much information in the session incurring memory overhead. This the more secure of the two though as the actual data never gets to the client.
    Option 2 is much less secure but very lightweight. You can use any cipher you wish. The more often you change the key, the more secure this option is. Changing a key with every request is best.
    Neither solution is perfect but hopefully one is sufficient.

  • How can I share values between different jsp pages?

    Hi,
    I'm doing a jsp, bc4j application (JDeveloper 9.0.3), and I need to share some values between different jsp pages. To do this,
    I have used the tag <jsp:usebean.....></jsp:usebean> in this way:
    on pageone.jsp
    <jsp:useBean id="param" scope="session" class="MyPackage.Parameters" ></jsp:useBean>
    on pagetwo.jsp     
    <jsp:useBean id="param" scope="session" class="MyPackage.Parameters" ></jsp:useBean>
    and so on, in order to refer to the same instance of the class "Parameters".
    After deploying, the application works well only if the client is the same pc where the AS resides, otherwise the variables of "Parameters" are null.
    Please, could you help me?
    Thanks
    Nunzio.

    I am seeing an indication on 9.0.3 that static includes are not static, but instead always dynamic. The compiler generates a call to the included page, and doesn't include the content in the calling page as it should.

  • How to upload an image from servlet/jsp into server from clients machine?

    can anybody send me the code to upload image from client to server using servlet/jsp.
    i'm using tomcat server.

    You can use the [Apache Commons FileUpload API|http://commons.apache.org/fileupload/] to upload files using Java.
    Here is a Filter example which uses the FileUpload API to process the request and stores the regular request parameters back in the ParameterMap of the request and puts the uploades files as attributes of the request: [http://balusc.blogspot.com/2007/11/multipartfilter.html] Just define it once in web.xml and you can continue writing the servlet logic as usual.

  • How to exchange information between the MIDlets in the same MIDletsuite

    hi all,
    I want to exchange the information between the two MIDlets in the same suite.can it possible to have the communication between the two midlets in the same suite.
    I read the articles about that communication but they have also mention that MIDP was not having specification about that.It was vendor dependent.
    Is that true,if true how i can communicate with the other midlet in the same suite.
    please help me in this aspect
    thanks in advance
    lakshman

    hi vilyams,
    Thanks for your reply. Upto now i have tried in different ways to get the communication between the MIDlets.
    You have given me the new Idea I will try that.
    Because of the heavy coding in the Canvas class I am getting the OutofMemory Exception.
    I have tried with the Two different Canvas classes even then it was the same problem.
    I want to know one thing where the code will store the details in the phone. is there anyway to specify the Exact location(by us) to store the content in the phone.
    please show me some light about the RMS and its functionality and some stuff regarding that
    thanks in advance
    lakshman

  • Exchange POST data between servlets?

    Hello all
    First of all, my apologies for my English. This is the first time writing to forum.
    I�m new to java and I need a little help with servlets.
    I have the servlets A, B and C.
    Servlet A just display a page with a form tag witch send the data to Servlet C via POST method. What I want is to intercede the Servlet B between them and check the integrity of those POST data.
    For example: Servlet A send data to Servlet B via POST method, Servlet B check the integrity of those data, and finally Servlet B send those data to Servlet C via POST method.
    For now the only I have done is to send the data to B and transfer the data to C with GET method.
    How can I send data with POST method in a servlet?
    The code so far:
         String urlstr = new String();
         String str1 = request.getParameter("st_name");
    String str2 = request.getParameter("st_birth");
    String str3 = request.getParameter("st_class");
    ��some check ����
         urlstr = "/student/check_st?st_name=" + str1 + "&st_birth=" + str2 + "&st_class=" + str3;
         response.sendRedirect(urlstr);
    Thanks in advanced.
    Ilias

    You should use the RequestDispatcher.forward(request,response) method.
    For example, inside Servlet B do this:
    public void doPost(ServletRequest request, ServletResponse response) {
        ... validate parameters ...
        RequestDispatcher dispatcher = request.getRequestDisplatcher("ServletC");
        dispatcher.forward(request,response);
    }This prevents an extra request-response cycle to the client and between the .forward() and .include() methods of the RequestDispatcher, should be considered the preferred way of server-side redirection unless there is a specific need to go to the client first.
    See the J2EE API:
    http://java.sun.com/javaee/5/docs/api/

  • How to upload files through a servlet/jsp form?

    anyone know basically how to do this?
    i need to write a simple jsp form the can browse for a file on my machine, then upload it to a server in the usual html form manner.
    is this done with an i/o stream?
    thanks for any help!
    robSmyth
    [email protected]

    jspSmart has a free upload component you can use for HTTP file uploading. (http://www.jspsmart.com )
    Also, O'Reilly has an open source package you can use. (http://www.oreilly.com or http://www.servlets.com )
    Another option is dotJ, which has an upload tag in its tag library. Benefit of this library is that it has a much more compehensive set of JSP tags. (http://www.dotjonline.com )

  • How to exchange big files between mac users through the internet?

    How can we send and receive big files between Mac users (apart from Dropbox) ?

    If you aren't on the same local network (which I assume you aren't), then the easiest solution is to use Google.
    If you simply google "sending large files" you will get hundreds of suggestions/applications.
    Ie Dropbox, Google, YouSendIt, FTP, etc

  • How to create crystal reports using servlets/jsp

    plase any body help me how to create and interact with crystal reports using java

    To use the inproc RAS SDK with CR.NET, you'd have to purchase either (1) Crystal Reports XI Release 2 Developer edition, and apply Service Pack 2 or above, or (2) Crystal Reports 2008 (not Crystal Reports Basic that comes with Visual Studio 2008).
    Sincerely,
    Ted Ueda

  • How to pass Parameters between two forms

    im trying to do this but i could not find any way for this.
    can any one help me how can i pass parameters between two forms
    in forms4.5. any help will be appreciated
    thanks.
    null

    Global variables can be used, but you can do what the online help
    says ...
    Parameters are passed to called forms by means of a parameter
    list. A parameter list is a named programmatic construct that is
    simply a list of parameter names (called keys) and their values.
    You can pass parameter values to forms invoked by the built-in
    subprograms CALL_FORM, OPEN_FORM, and NEW_FORM. In addition, you
    can pass parameter values to other Oracle tools with the
    RUN_PRODUCT procedure.
    A parameter you include in a parameter list can be either a text
    parameter or a data parameter. The parameter type determines how
    its value is interpreted.
    Text Parameters The value of a text parameter being passed to a
    called product is a CHAR string that can represent the following:
    n a user-defined form parameter defined in a form invoked
    by the CALL_FORM, OPEN_FORM, or NEW_FORM built-in subprograms
    n a command line or user-defined parameter for a product
    invoked with the RUN_PRODUCT built-in subprogram
    Data Parameters The value of a data parameter being passed to a
    called product is always the name of a record group defined in
    the current form. (A record group is a data structure that
    stores records derived from a query or through programmatic
    assignment.) Data parameters are used to pass data to products
    invoked with the RUN_PRODUCT built-in subprogram. You cannot
    pass data parameters to forms.
    The following table shows the structure of a parameter list that
    contains four parameters:
    Key Paramtype Value
    CITY Text_Parameter 'BOGOTA'
    CATEGORY Text_Parameter 'EXPORTS'
    MULTIPLIER Text_Parameter '.0275'
    NEW_DATA Data_Parameter 'RECORD_GROUP8'
    arun reddy (guest) wrote:
    : im trying to do this but i could not find any way for this.
    : can any one help me how can i pass parameters between two forms
    : in forms4.5. any help will be appreciated
    : thanks.
    null

  • How to pass parameters between two xterm windows?

    Hi,
    I would like to know how to pass parameters between two xterm windows where there are two independence processes running on them respectively ? Would appreciate if any one out there can advise me . Thanks.

    Global variables can be used, but you can do what the online help
    says ...
    Parameters are passed to called forms by means of a parameter
    list. A parameter list is a named programmatic construct that is
    simply a list of parameter names (called keys) and their values.
    You can pass parameter values to forms invoked by the built-in
    subprograms CALL_FORM, OPEN_FORM, and NEW_FORM. In addition, you
    can pass parameter values to other Oracle tools with the
    RUN_PRODUCT procedure.
    A parameter you include in a parameter list can be either a text
    parameter or a data parameter. The parameter type determines how
    its value is interpreted.
    Text Parameters The value of a text parameter being passed to a
    called product is a CHAR string that can represent the following:
    n a user-defined form parameter defined in a form invoked
    by the CALL_FORM, OPEN_FORM, or NEW_FORM built-in subprograms
    n a command line or user-defined parameter for a product
    invoked with the RUN_PRODUCT built-in subprogram
    Data Parameters The value of a data parameter being passed to a
    called product is always the name of a record group defined in
    the current form. (A record group is a data structure that
    stores records derived from a query or through programmatic
    assignment.) Data parameters are used to pass data to products
    invoked with the RUN_PRODUCT built-in subprogram. You cannot
    pass data parameters to forms.
    The following table shows the structure of a parameter list that
    contains four parameters:
    Key Paramtype Value
    CITY Text_Parameter 'BOGOTA'
    CATEGORY Text_Parameter 'EXPORTS'
    MULTIPLIER Text_Parameter '.0275'
    NEW_DATA Data_Parameter 'RECORD_GROUP8'
    arun reddy (guest) wrote:
    : im trying to do this but i could not find any way for this.
    : can any one help me how can i pass parameters between two forms
    : in forms4.5. any help will be appreciated
    : thanks.
    null

  • Transfering data between servlets

    hi
    how would i transfer data between servlets - Im creating a form (form1) which asks the user to enter information - the user then submits, and this takes them to the next form (form2) - i need to transfer the data from form1 to form2 (ie. name, lastname). code follows
              // set content type
              response.setContentType("text/html");
              // then write the data of the response
              out = response.getWriter();
              out.println("<HTML><HEAD><TITLE>" + Title + "</TITLE></HEAD><BODY BGCOLOR=white>");
              out.println("<H2>Customer Registration Form</H2>");
              //create link to servlet action = pathOfServlet?
              out.println("<FORM action = \"ServletExample1\">");
              out.println("First name: <input type=text name=\"name\" value=\"" + name + "\">");
              out.println("Last Name: <input type=text name=\"lastName\" value=\"" + lastName + "\"><P>");
              //value=\"female\" -- forward slash enters html/java and ends java
              out.println("Male<input type=radio name=\"gender\" value=\"male\"> ");
              out.println("Female<input type=radio name=\"gender\" value=\"female\"><P>");
              out.println("Telephone: <input type=text name=\"phone\" value=\"" + phone + "\">");
              out.println("Email: <input type=text name=\"email\" value=\"" + email + "\"><P>");
              out.println("<INPUT TYPE=SUBMIT><P>");
              out.println("</FORM>");
              // then write the data of the response
              out = response.getWriter();
              out.println("<HTML><HEAD><TITLE>" + Title + "</TITLE></HEAD>\n");
              out.println("<BODY BGCOLOR=white>");
              out.println("<H3>Credit Card Information</H3>");
              out.println("<FORM>");
              out.println("First name: <input type=text name=\"name\" value=\"" +should i link here+ "\">");
              out.println("</BODY></HTML>");

    Have you tryed using the request parameter? It should contain what you seek, I think.
    Here for example;
    String firstName = request.getParameter("name");
    String lastName = request.getParameter("lastname");Use that in the second form, which should get its parameters from form1.

  • 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.

  • How can pass information between 2 par file in iView???

    Hello,using PDK i've have created an iview calling 2 .par file, the first par file contains a menu that the user selects a products and then when press load button generates a table with information. The table with information is generated in second .par file, that collects the information passed by the menu (through beans) and with a BAPI generates the table. I made it because the menu must be separated in one frame, and the table in other...(and the first frame must displace, how a html frame)
    The question, how can pass information between two par files or if are another method to made 2 frames????
    I'm using jsp,HTMLB .
    Thanks.

    Hi,
    try to have a look to the docs contained in this zip file.
    They explain how to implement a portal component, a portal service and how to implement comunication between portal components, using POM and other features.
    Maybe could be a good starting point for you
    the file is
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/documents/a1-8-4/component and service creation tutorial.zip
    Ciao
    Roberto

  • How to implement Servlet/JSP in PAR to be used standalone (not as iView)

    Hi everyone!
    I want to develop a Servlet (or a JSP) that is part of my PAR with the main iView because it will be called in an iframe within that iView.
    1. It has to be possible to call it directly from the Browser (iframe).
    2. The output has to be exactly what i generate in it, meaning there must not be added anything to the output by the portal.
    3. Because it uses the same classes that the iView itself is made of, I think it has to be part of the same PAR file.
    4. Creating the servlet in an EAR and then copying (duplicating) the class files from the iView into it or putting them into their own jar and copying that into the PAR and the EAR is not really an option (for maintenance and development reasons)
    What I tried so far:
    -- implement the functions in a JSP which I put into dist/jsp => JSP is accessible from the browser but importing classes from the src.core is not possible (neither from default package, nor from any other named package in there)
    -- implement in a JSP which I put into dist/PORTAL_INF/pagelet => JSP is not accessible from the browser (tried with the URL from IResourceInformation), so I don't know whether the imports would work
    -- implement in a Servlet class in the src.core => don't know how to access that from the browser or how to configure it to be accessible or if this is possible at all
    Maybe I am looking at the whole thing from the wrong side and the solution is something completely different from what I thought.
    I have looked for information on this for nearly 8 hours now but did not find anything that really helped me. So any help is really appreciated.
    Kind regards, Roland

    First, thanks for the links.
    But
    3.      Put the compiled servlet class in the private lib or classes folder.
    seems not very pratical to me as you always have an additional manual step to do after each and every little change and therefore another source for possible errors. Also you have to switch perspectives in Developer Studio to do the copying. Isn't there a way to use the already existing class files from the iView?
    Another question away from that: How do I access such a servlet via the web browser? What is the URL to it?
    Quite trivial, but didn't find information on that, too.
    Thanks anyway, Roland

Maybe you are looking for

  • My PDF export has been terminated due to invalid former credit card. how

    My PDF Export has been terminated due to invalid former credit card. How I can continue by means of pay by new credit card?.

  • Integration between two HCM 9.1 systems

    Hi, Our design requires two HCM 9.1 systems to be configured. One will host the core HCM data and another will host the recruiting solutions. For easy reference, I will name HCM environment as HCM and the HCM environment which will be used for recrui

  • Delivery IDOC not getting generated

    Hi All, I have created an outbound delivery IDOC. The process is that the idoc should be trigerred as soon as the delivery is created/changed or deleted. I am having an issue. The idoc is getting trigerred as soon as the delivery is getting created b

  • Two level of tabs - only 1 level shows up

    Hi all, I have an application, previously set up without using tabs, but I added two level of tabs. It looks like everything is fine, but only the standard tabs are on the pages, not the parents. Invionment: Apex 4.1, Oracle 10gR2 on Windows 32 bit T

  • Retina Macbook pro free upgrade os x mountain lion

    I get the new retina macbook pro,so how will I get my free upgrade to osx mountain lion?