Passing variables to jsp

In what all ways we can pass variables to jsp??
I got one arraylist in my servlet(controller) and i have to send it to jsp page(view)...
one way of doing it is trough "session", is there any other way??
if yes .. which one is better??

Hi,
You can store your variable in 3 scopes in servlet and in 4 scopes in JSP
In Servlets you can do it in the following ways.
request scope
session scope
context scope
In Jsp you can do it in the following ways
request scope
session scope
context scope
and page scope
Request scope means, you can maintain the state only when the request is alive.
Session scope means, you can maintain the state only when the session is alive
similarly context , you can maintain the state only when the context is alive.
page scope is just for page.
I hope , you want these details. :)
bye for now
sat

Similar Messages

  • Passing Variables from JSP to a servlet

    Presently I have a small Web application where by users enter data onto a jsp Page , this data then gets passed onto a servlet which then updates a sql database through a call to a sql stored procedure
    While testing I determined that when there are multiple users, sometimes users records are getting crossed, some of my data, is getting written to someone elses record....
    any thoughts on the cause......

    below is the code to the servlet
    The jsp page is a typical jsp with text boxes etc,
    package cpri;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    public class viewfileinfoservlet extends HttpServlet {
      private static final String CONTENT_TYPE = "text/html";
      //Initialize global variables
      public void init() throws ServletException {
      //Process the HTTP Post request
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        Connection conn = null;
        CallableStatement stmt = null;
        String sErrorMessage = "";
        String sStatus = "PS";
        String sSin = "";
        String sPSin = "";
        String sBN = "";
        String sPBN = "";
        String sSurName = "";
        String sFirstName = "";
        String sLegalName = "";
        String sTradeName = "";
        String sAddress = "";
        String sCity = "";
        String sProv_Code = "";
        String sRTSO = "";
        String sPayment = "";
        String sGSPayment = "";
        String sCompliant = "";
        String sTX11Issued = "";
        String sFYEMM = "0";
        String sFYEDD = "0";
        String sGSTStatus = "";
        String sNotes = "";
        String sRecordID = "";
        String sFYE = "";
        String sRCode = "";
        String sPostalCode = "";
        String sRemoteUser = "";
        int intRecordID = 0;
        int intRemoteUser = 0;
        int i = 0;
        String sPayorPhone = "";
        String sPayorName = "";
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setBufferSize(10*1024);
        sErrorMessage = "";
        sRemoteUser = request.getRemoteUser();
        sRTSO = "0";
        if (sRemoteUser.indexOf("\\") != -1)
          intRemoteUser = sRemoteUser.indexOf("\\") + 1;
          sRemoteUser = sRemoteUser.substring(intRemoteUser);
        sGSTStatus = "";
        if ( request.getParameter("lstStatus") !=null)
          sStatus = request.getParameter("lstStatus").trim();
          if (sStatus.equals("PS"))
            sErrorMessage = sErrorMessage + "Was unable to confirm File Status." + "\n";
        else
          sErrorMessage = sErrorMessage + "Was unable to confirm File Status." + "\n";
      if ( request.getParameter("txtPayorName") !=null)
       sPayorName = request.getParameter("txtPayorName").trim();
    else
       sPayorName = "";
    if (request.getParameter("txtPayorPhone") !=null)
      sPayorPhone = request.getParameter("txtPayorPhone").trim();
    else
      sPayorPhone = "";
      if ( request.getParameter("txtSin") !=null)
        sSin = request.getParameter("txtSin").trim();
      else
        sSin = "";
      if ( request.getParameter("txtPSin") !=null)
        sPSin = request.getParameter("txtPSin").trim();
      else
        sPSin = "";
      if ( request.getParameter("txtPBN") !=null)
        sBN = request.getParameter("txtPBN").trim();
      else
        sBN = "";
      if ( request.getParameter("txtPPBN") !=null)
        sPBN = request.getParameter("txtPPBN").trim();
      else
        sPBN = "";
      if ( request.getParameter("txtSurname") !=null)
        sSurName = request.getParameter("txtSurname").trim();
      else
        sSurName = "";
      if ( request.getParameter("txtFName") !=null)
        sFirstName = request.getParameter("txtFName").trim();
      else
        sFirstName = "";
      if ( request.getParameter("txtLName") !=null)
        sLegalName = request.getParameter("txtLName").trim();
      else
        sLegalName = "";
      if ( request.getParameter("txtTName") !=null)
        sTradeName = request.getParameter("txtTName").trim();
      else
        sTradeName = "";
      if ( request.getParameter("txtAddress") !=null)
        sAddress = request.getParameter("txtAddress").trim();
      else
        sAddress = "";
      if ( request.getParameter("txtCity") !=null)
        sCity = request.getParameter("txtCity").trim();
      else
        sCity = "";
      if ( request.getParameter("txtProv_Code") !=null)
        sProv_Code = request.getParameter("txtProv_Code").trim();
      else
        sProv_Code = "";
      if ( request.getParameter("txtPostal") !=null)
        sPostalCode = request.getParameter("txtPostal").trim();
      else
        sPostalCode = "";
      if ( request.getParameter("lstRecCode") !=null)
        sRCode = request.getParameter("lstRecCode").trim();
      else
       sRCode = "";
      if ( request.getParameter("txtRTSO") !=null)
        sRTSO = request.getParameter("txtRTSO").trim();
      else
        sRTSO = "";
      if ( request.getParameter("txtsPayment") !=null)
        sPayment = request.getParameter("txtsPayment").trim();
      else
        sPayment = "0";
      if ( request.getParameter("txtGSPayment") !=null)
        sGSPayment = request.getParameter("txtGSPayment").trim();
      else
        sGSPayment = "0";
      if ( request.getParameter("lstCompliant") !=null)
        sCompliant = request.getParameter("lstCompliant").trim();
      if ( request.getParameter("lstTX11Issued") !=null)
        sTX11Issued = request.getParameter("lstTX11Issued").trim();
      sFYEMM = "";
      if ( request.getParameter("txtMM") !=null)
        sFYEMM = request.getParameter("txtMM").trim();
      sFYEDD = "";
      if ( request.getParameter("txtDD") !=null)
        sFYEDD = request.getParameter("txtDD").trim();
      if ( request.getParameter("lstGSTStatus") !=null)
        sGSTStatus = request.getParameter("lstGSTStatus").trim();
      if ( request.getParameter("Notes") !=null)
        sNotes = request.getParameter("Notes").trim();
      else
        sNotes = "";
      if ( request.getParameter("RecordID") !=null)
        sRecordID = request.getParameter("RecordID").trim();
      if (sFYEMM.equals("0") && sFYEDD != "0")
        sErrorMessage = "Was unable to confirm FYE." + "\n";
      if (sFYEDD.equals("0") && sFYEMM != "0")
        sErrorMessage = "Was unable to confirm FYE." + "\n";
      sFYE = "1999" + "-" + sFYEMM + "-" + sFYEDD;
      if (sStatus.equals("PA")||sStatus.equals("A")||sStatus.equals("PCR")||sStatus.equals("PCU"))
         // check for errors
           try
             i = Integer.parseInt(sRTSO);
           catch (NumberFormatException ex)
             sErrorMessage = sErrorMessage + "Recipient TSO must be a numeric field and is required field when file  is being closed." + "\n";
         if (sRCode.equals("0"))
           sErrorMessage = sErrorMessage + "Recipient Code is a required field when file is being Closed." + "\n";
      if (sErrorMessage.length()!=0)
              //display error page
              request.setAttribute("ERRORS", sErrorMessage);
              request.getRequestDispatcher("ViewFileInfoError.jsp").forward(request,response);
              out.flush();
              return;
      else
              try
                conn = CPRI_Connection.GetSQL_APPConnection();
                String call = "{call usp_UpdateCPRIRecord(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
                stmt = conn.prepareCall(call);
                stmt.setString(1, sRecordID);
                stmt.setString(2, sStatus);
                stmt.setString(3, sSin);
                stmt.setString(4, sPSin);
                stmt.setString(5, sBN);
                stmt.setString(6, sPBN);
                stmt.setString(7, sSurName);
                stmt.setString(8, sFirstName);
                stmt.setString(9, sLegalName);
                stmt.setString(10, sTradeName);
                stmt.setString(11, sAddress);
                stmt.setString(12, sCity);
                stmt.setString(13, sProv_Code);
                stmt.setString(14, sRTSO);
                stmt.setString(15, sPayment);
                stmt.setString(16, sGSPayment);
                stmt.setString(17, sCompliant);
                stmt.setString(18, sTX11Issued);
                stmt.setString(19, sFYE);
                stmt.setString(20, sGSTStatus);
                stmt.setString(21, sRCode);
                stmt.setString(22, sPostalCode);
                stmt.setString(23, sNotes);
                stmt.setString(24, sRemoteUser);
                stmt.setString(25, sPayorName);
                stmt.setString(26, sPayorPhone);
                stmt.registerOutParameter(27, java.sql.Types.INTEGER);
                stmt.execute();
                if (stmt.getInt(27) != 0) {
                  intRecordID = stmt.getInt(27);
                else {
                  intRecordID = 0;
                sRecordID = String.valueOf(intRecordID);
               stmt.close();
               if (conn !=null){
                 try {
                   conn.close();
                 }catch (SQLException ex1){
                   //trow new Servlet exception
             catch(SQLException ex){
               throw new ServletException(ex);
        //RequestDispatcher disp;
        //disp = getServletContext().getRequestDispatcher("EventConfirmation.jsp");
        request.setAttribute("Action",sRecordID);
        request.getRequestDispatcher("ViewFileInfo.jsp").forward(request, response);
        //out.println("sEventID:" + sEventID + "<br>");
        //disp.forward(request, response);
      //Clean up resources
      public void destroy() {
    }

  • Passing variables from JSP to XSL

    Hi;
    I need to pass some variables with string value in them to an xsl page to store them in a <param..> tag... ive so far been unsuccessful at that, the following are my codes.. : Does anyone know how to pass it directly into the xsl page ?...
    jsp page :
    <%
                                                                     String compNames;
                                                                     String[] listRight;
                                                                     compNames = (String)session.getAttribute("compNames");
                                                                     listRight = request.getParameterValues("listRight");
                                                                                         String yr1 = listRight[0];
                                                                                         String yr2 = listRight[1];
                                                                                         String yr3 = listRight[2];
                                                                                         String yr4 = listRight[3];
                                                                                         String yr5 = listRight[4];
                                                                                         pageContext.setAttribute("yr1", yr1);
                                                                                         pageContext.setAttribute("yr2", yr2);
                                                                                         pageContext.setAttribute("yr3", yr3);
                                                                                         pageContext.setAttribute("yr4", yr4);
                                                                                         pageContext.setAttribute("yr5", yr5);
                                                                                         pageContext.setAttribute("compN", compNames);
                                                                     %>
    xsl page :
    <xsl:param name="CoCode"><core:param name="compN" value="${compN}"/></xsl:param>
         <xsl:param name="yr1"><core:param name="yr1" value="${yr1}"/></xsl:param>
         <xsl:param name="yr2"><core:param name="yr2" value="${yr2}"/></xsl:param>
         <xsl:param name="yr3"><core:param name="yr3" value="${yr3}"/></xsl:param>
         <xsl:param name="yr4"><core:param name="yr4" value="${yr4}"/></xsl:param>
         <xsl:param name="yr5"><core:param name="yr5" value="${yr5}"/></xsl:param>

    and to display the xsl, ive used to following Include code :
    <jsp:include page ="./ratios.xsl"></jsp:include>
    i dont need to link it together with as xml as ive already done so in ratios.xsl file... i think there might be some mistake in using the include code... can anyone point out to me if im wrong... thanks

  • Passing variables from JSP to workflow

    I want to pass some variables from my JSP forms to a workflow. The workflow is triggered when I call processLaunch.jsp with the name of the workflow. I couldn't figure out a way to have the input fields in my JSP form passed to the workflow.
    If anyone can provide me with some answer, I'd greatly appreciate it.

    <Property name='postURL'>
    <block>
    <concat>
    <s>user/processLaunch.jsp?id=</s>
    <ref>ConstantData.REGISTERED_PROCESSES.WF_COMMON_ITARUPDATE</ref>
    </concat>
    </block>
    </Property>
    I have this code on the form...how should I pass a op_enduserId from here to my workflow. Can I pass it by query string &op_enduserId=enduserId

  • I am an ASP programmer and need help passing variable in JSP

    When I pass a value using a variable string that grabs the user name of a current windows session it adds spaces after each character. it should pass jdt3 and it passes j d t 3. It is grabbing the correct info. It writes the value to a web page correctly though. I really appreciate the assistance.
    <%@ page import="sun.misc.BASE64Encoder" %>
    <p><h1>Network Windows USERNAME without any login (ie)</h1></p>
    <%
    String auth = request.getHeader("Authorization");
    if (auth == null) {
    response.setStatus(response.SC_UNAUTHORIZED);
    response.setHeader("WWW-Authenticate", "NTLM");
    return;
    if (auth.startsWith("NTLM ")) {
    byte[] msg =
    new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
    int off = 0, length, offset;
    String s;
    if (msg[8] == 1) {
    off = 18;
    byte z = 0;
    byte[] msg1 =
    {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S',
    (byte)'S', (byte)'P', z,
    (byte)2, z, z, z, z, z, z, z,
    (byte)40, z, z, z, (byte)1, (byte)130, z, z,
    z, (byte)2, (byte)2, (byte)2, z, z, z, z, //
    z, z, z, z, z, z, z, z};
    response.setStatus(response.SC_UNAUTHORIZED);
    response.setHeader("WWW-Authenticate", "NTLM "
    + new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim());
    return;
    else if (msg[8] == 3) {
    off = 30;
    length = msg[off+17]*256 + msg[off+16];
    offset = msg[off+19]*256 + msg[off+18];
    s = new String(msg, offset, length);
    //out.println(s + " ");
    else
    return;
    length = msg[off]*5 + msg[off];
    offset = msg[off+3]*5 + msg[off+2];
    s = new String(msg, offset, length);
    //out.println(s);
    length = msg[off+9]*5 + msg[off+8];
    offset = msg[off+11]*5 + msg[off+10];
    s = new String(msg, offset, length);
    out.println(s + "</SPAN>");
    String redirectURL = "http:www.intranet.com?UName="+s;
    response.sendRedirect(redirectURL);
    %>
    </BODY>

    Open AirPort Utility on the PC, select the Airport Extreme and click Manual Setup
    Click the Advanced icon
    Click the Port Mapping tab
    Click the + (plus) button at the bottom of the connection list to set things up
    Reference pages 49-51 in the Apple AirPort Networks guide for more info
    IF.....you do not see a Port Mapping tab when you click the Advanced icon, then that would mean that the AirPort Extreme is in Bridge Mode and the main routing functions for the network are being provided by another device.
    You will need to set up the port mapping on that device, which is likely your modem/router or gateway.

  • How to pass javascript variable to jsp function

    i want to check which table header (that is <th> in html )is clicked and based on that a jsp funtion do a query in database and should show records in sorted way according to which column head is clicked.
    Table is created in html.
    My function is
    Vector varray = workcaseid.getWorkcaseId(Long.parseLong(MasterAccountNumber),SelectedColumn);
    <table border="1">
              <th ><label onClick="<%SelectedColumn="workcase_id";%>">Workcase Id</label></th>
              <th><label onClick="<%SelectedColumn="status_id";%>">Status</label></th>
    <tr><td>etc</td></tr>
    </table>

    im using bean for business login, following mvc model,and i think mvc is one of good design practice to use.
    <jsp:useBean id="workcaseid" scope="session"class="beanFiles.SearchWorkcaseId" />
    varray = workcaseid.getWorkcaseId(Long.parseLong(MasterAccountNumber),SelectedColumn);
    just tell me whether it is possible to pass javascript variable to jsp variable or not.i can do it by using hidden input type,using form and submit button.

  • Passing variable from one JSP to another

    Hi....
    I am working on customizing Oracle Application(istore).
    I need to pass variable from 1 JSP to another.
    JSP 1 contains the following line of code:
    <INPUT type="HIDDEN" name="soldtoCustPartyName" value="<%=soldtoCustPartyName%>">
    How can I pass this to another JSP Page. The other JSP should take the 'soldtoCustPartyName' and find out the primary address country.
    So please help me in getting variable passed from 1st JSP to next.
    By default, 1st JSP is not fwded to 2nd JSP.
    This is very very urgent...Please help.....

    When you push the submit button on jsp1 - it goes to jsp2?
    ie
    // in jsp1.jsp
    <form action="jsp2.jsp">
    <INPUT type="HIDDEN" name="soldtoCustPartyName" value="<%=soldtoCustPartyName%>">
    <input type="submit">
    </form>
    //Then in jsp2.jsp all you need is
    request.getParameter("soldtoCustPartyName");This will pick up the value that is coming from the hidden field on jsp1

  • Passing variables between data tag and JSP-scriptlets

    Hi,
    There were some questions about this issue. However, the answers were not satisfactory.
    I would like to assign the value returned from data tag to a variable in JSP-scriptlets as follows:
    <%@ taglib uri="/webapp/DataTags.tld" prefix="jbo" %>
    <br>
    <jbo:ApplicationModule id="isae.OPKv1.OPKv1Module" configname="isae.OPKv1.OPKv1Module.OPKv1ModuleLocal" username="t1" password="t1"/>
    <br>
    <!-- a record is selected -->
    <jbo:DataSource id="ds" appid="isae.OPKv1.OPKv1Module" viewobject="AePk100View" whereclause=" <%= ic %> " />
    <br>
    <jbo:Row id="privRow" action="CURRENT" datasource="ds">
    <%
    String privName = (String) privRow.getAttribute("ArBau325"); // this is the suggestion of William Dwight (Jan 21, 2001 this forum)
    %>
    </jbo:Row>
    This code did not work. I have obtained an error :
    java.lang.ClassCastExeption
    Any help would be greatly appreciated.
    Thanks

    The value return by the getAtribute might not be of type String. If you want to return a String value you need to convert the value using the toString method as follow:
    <jbo:Row id="privRow" action="CURRENT" datasource="ds"/>
    <%
    String privName = "";
    Object obj = privRow.getAttribute("ArBau325");
    if (obj != null)
    privName = obj.toString();
    %>
    Also note that you do not need to put the scriplet code inside the body of the row tag.
    Charles.

  • How can i assign a Javascript variable to JSP variable

    Hi guys
    how i can assign a javascript variable to jsp expression.,
    e.g.,
    <input type = "button" value = "Add more" onclick = "return submitform1('<%=s%>')">
    function submitform1(String s)
          var s1 = s
    document.form1.action = "../intimation.do";    /* Here i want to pass the value s1 to jsp or servlets without using hidden fields and Query string*/
           document.form1.submit();
          return false;
    /*  i want to pass the values thru session whether it is possible */
    pls give sample code
    Reply
    Marimuthu

    You don't have the session.
    All you have is HTTP.
    The only way to communicate from the client to the server is via an HTTP request. The only way to send a value like that is with a parameter.
    Using a form with method="submit" as mentioned will pass the parameters without displaying them in the url bar (is that what you wanted?)

  • Using JSTL variables in JSP or Javascript. Possible ?

    Hi All,
    Is it possible to share or use the variables which are declared are used by JSTL in JSP expression or scriplet code and in Java Script.
    Example:
    This Works:
    <fmt:set var="test" value="JSTL" />
    <fmt:out value="${test}" />
    But, this gives error:
    <% out.println(test) %>
    And passing the value of variable 'test' to Java Script code also gives error.
    How to use JSTL variables in JSP and in Javascript ?
    Yours,
    Sankar.B

    By default, JSTL variables are kept in servlet
    attributes. Default is to store it in the page
    context. You can make it request/session/application
    scope as required by an attribute of the set tag.Hi there,
    Can anyone advise how to access JSP variables in JSTL?
    Can it be done as the same method through request/session/application scope?
    Thnks...

  • Parse A Variable From JSP to JSP

    hi all,
    how can i parse a variable from jsp page to another jsp page. i do not call jsp page . so how can i do this

    do u mean passing???
    try scope application

  • Opendoc : to pass  variable doesnt work

    hy,
    i want pass variable from one report to another
    i use this formula :
    "<a href='http://myserver:8080/businessobjects/enterprise115/desktoplaunch/opendoc/openDocument.jsp?sIDType=CUID&iDocID=Ad6ICMdlQV9ElilBHmITZpg&lsSpays=u201D[Pays]u201D&sRefresh=Y&sWindow=New'>detail</a>"
    pays is a prompt
    [pays] is my query object in a table
    when i clic on detail i want open detail report with prompt pays=value  line
    it's doesnt work my prompt is nul
    thank's
    Edited by: PHILIPPE REMIS on Oct 20, 2009 5:34 PM

    it's ok now

  • Equating a passed variable to another variable??

    I have a simple 3 part setup as follows...
    1 JSP, 1 Java Class, 1 Interface for the class
    I want the JSP file to pass a variable to the java class which contains the name of a variable in the interface. (e.g. a String called "name", the variable name in the interface contains "Bob Smith") How do I get java to equate what is in the passed variable ("name") to what is contained in the name variable of the interface("Bob Smith"). Hopefully I explained this with enough detail to understand, but if I didnt, let me know.
    -Adam Wachtel

    Nevermind, I'm going to switch the flow of data so I dont have to do that.

  • Get javascript variable in JSP

    Hi all,
    can anybody tell me- how to get javascript variable in JSP,
    in the same file (JSP).
    Is this possible.
    I can use JavaScript to get the value,
    but then I have no way to get that to the JSP code.
    Please give the appripriate answer with code.
    Thanks
    amitindia

    Hi all,
    Thanks for your quick response.
    So u are right that we can not call javascript variable
    in the same JSP. and pass them to the bean class.
    So what I did --- I get java script variable in another JSP using
    request.getParameter(); and then redirected to previous JSP.
    and I have solve my problem.
    Actually I had to call bean class and pass varible to the bean
    method but I was getting the same problem that I disscussed but now it
    has been solved.
    Thanks again for participation
    amitindia

  • Passing variable values to the navigation block

    Hi WAD Experts,
      I have a requirement regarding passing variable values to the navigation block. User requirement is first give the selections on the selection screen and then after executign output should display in browser. In the output page we have a navigation block. So when user gives selections those selections should also populate in the navigation block. Your help will be appreciated.
    Prasad.

    Hi,
    if your variable is 'Changeable at Query Navigation' the chosen values will appear in the Navigationblock.
    Variables which are 'Not Changeable at Query Navigation'
    will not appear.
    You can set this Property when you create a Variable.
    Kind Regards,
    Alican Polat

Maybe you are looking for

  • Adobe worst company ever for customer support?

    Whats the deal?  I ordered the upgrade for Soundbooth from 3 to 4, a supposed download.  Only it doesn't have one. You download 500 mb of garbage, games, demos, benchmark junk, but no Soundbooth.  Supposedly customer service is sending me the disc be

  • Lion 10.7.5 cant connect to printer via Buffalo print server

    Hi everyone, I'm at my wits end with this one having spent over 20 hours on it. I have a Macbook Air running Lion 10.7.5 and a Macbook running OSX 10.6.8.  I have a Photosmart 8050 printer attached to a Buffalo Linkstation Live LS-CH1 running firmwar

  • Calling an AS400 RPG program to create users on AS400

    Hi, our customer has a custom application on AS400. To create users for this application, the customer uses a RPG program that both creates the AS400 user, populates the application custom tables, and do other stuff needed for the user definition. No

  • [SOLVED] How to install KMail 2?

    Has anyone had experience installing kdepim-kmail2 on Arch? This is what I did: 1) Downloaded both tarballs from ftp://ftp.kde.org/pub/kde/unstable/kdepim/4.5.94.1/src/ 2) Extracted them. CD into directory, type cmake ./ 3) After ~15 mins of compilin

  • Delete+attr+value operations not replicated

    Hi, I have a replicated environment and a really weird situation in it. Replication agreements works properly except for operations like: changetype: modify delete: profileoutputfrequency profileoutputfrequency: 1 When I send to the server the same o