POST variables in a JSP page

I have a JSP page which recieves a number of arguments.
One of those arguments in a desination URL. The JSP page picks this up and then uses a response.sendRedirect(URL) call to forward the user to this page.
Is there anyway of passing these other arguments across to this destination page as hidden variables.
I dont want to append these variables to the existing URL as they should remain hidden.
What other methods can I use for these variables to accompany the sendRedirect call or is there a different approach thats required for this case ??
Thanks in advance,
Richard

You can try this. It works.
out.println("<html>");
out.println("<head>");
out.println("<title></title>");
out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
out.println("</head>");
out.println("<body bgcolor=\"#FFFFFF\" text=\"#000000\" onLoad=\"javascript:document.forms[0].submit();\">");
out.println("<form name=\"formulario\" method=\"post\" action=\"http://PutHereTheURLOfsendRedirect\">");
// Put here your hidden variables.
out.println("<input type=\"hidden\" name=\"hiddenField1\" value=\"hiddenvalue1\">");
out.println("<input type=\"hidden\" name=\"hiddenField2\" value=\"hiddenvalue2\">");
out.println("</form>");
out.println("</body>");
out.println("</html>");

Similar Messages

  • How to pass variables between 2 jsp pages-help

    Hi,
    I have a question like this.
    As an example consider I have 3 .jsp pages.
    page1.jsp - In this html form it has some textboxes to enter employee details.
    page2.jsp - In this page it has a "PRINT" button which allows the user to click.
    page3.jsp - A new popup window which having the same content as page2.jsp, but without the PRINT button.
    But my problem is this. In this page3.jsp,it should be display the entered textbox values as page2.jsp. But these values are not displaying here. They display as NULL.
    I use as follows, but it still not working.
    <%= request.getParameter("effDate")%>.
    Could you please tell me how to hold these values when I came from page2 to page3.
    I'm using JSP 1.2 with javaBeans.
    Thanks.

    Well,
    If you are popping up a new window, and you insisting on pulling the data out of the request's parameter map. Then you will need to add the values to the query string of your url.
    window.open("http:localhost/page3.jsp?itemOne=itemOneValue&itemTwo=ItemTwoValue, '', '');
    Alternative Option:
    When posting from page 1 to page two, store your information into session scope
    request.getSession().setAttribute("valeuOne", "valueOneValue");
    Then instead of pulling from the paramter map, use request.getSession().getAttribute("valueOne") in your third page.
    Hope that helps.
    Thanx
    Cardwell

  • Post messages on the jsp page

    This is my jsf(jsp) page:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
    <%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <f:view>
    <h1 align="center">File Selection Page</h1>
    <h:panelGroup>
    <form id="uploadForm" method="post" action="Multipart.do" enctype="multipart/form-data">
        Specify your name:<br />
        <input type="text" name="name"><br /><br />
        Specify your files: <br />
        <input type="file" name="file1"><br /><br />
         <input type="file" name="file2"><br /><br />
         <input type="file" name="file3"><br /><br />
        <input type="file" name="file4"><br /><br />
    <br><br>
    <center>
    <input type="submit" name="Submit" value="Submit Your Files">
    </center>
    </form>
    </f:view>
    </body>
    </html>I am using apache commons multipart file upload. How do I post success or failure messages to this page?
    As you see I am using a servlet(not shown - which uses Faces Context to populate the messages). Not sure how to get these out in the jsp page.
    Thanks,
    Sonia
    Edited by: sun_sonia on Nov 23, 2009 2:42 PM

    You're using plain HTML <input type="file"> elements. Use Tomahawk's <t:inputFileUpload> components instead of you want to make use of JSF's validation and messaging capabilities.
    If you insist in using a servlet instead of a bean for this, then just do all the usual JSP/Servlet way. My suggestion would be to hold a Map<String, String> which contains the fieldname-message pairs which you store in the request scope and then use the usual JSP/EL way to display them.

  • Need help passing variables to another jsp page

    I am working in a shopping cart with multiple lines and I am wanting to pass 2 variables to another page which is accessed from a link.
    What I have so far is the following:
    This is on the shopping cart JSP page with the link
    <input type="hidden" name="shopCartReqDate1<%=i%>" id="shopCartReqDate1<%=i%>" value="<%= retVals[9] %>">
    <input type="hidden" name="shopCartExpDate1<%=i%>" id="shopCartExpDate1<%=i%>" value="<%= retVals[10] %>">
    Need it Earlier?
    I am wanting to pass it to the HAC_Help_Text_Need_it_Earlier.jsp page
    Right now on the HAC_Help_Text_Need_it_Earlier.jsp page I have the following code:
    String shopCartReqDate1 = IBEUtil.nonNull(request.getParameter("shopCartReqDate1"));
    String shopCartExpDate1 = IBEUtil.nonNull(request.getParameter("shopCartExpDate1"));
    Do I need to create a function and do a document.getElementById?
    Thanks for the help!

    As far as I understand your question You don't have to use document.getElementById. Just submit the form and then on the next page You'll just pull the variables out from the request object.

  • Same variable on every JSP page

    Hi All,
    I'm just a beginner with JSP so excuse me if this is a 'stupid' question.
    I'm building an Application that uses MySQL database everything works ok, but
    I would like to know if there is a way to have a variable that I can use on every page.
    The reason is, is because I have lots of pages (and growing) where I have the
    database connect string with username password, but due to security reason
    the user/pass for the database will change every now and then.
    I'm familiar with Coldfusion and in Coldfusion you can setup an Application.cfm file. This file is called before every other .cfm file. Is there something like that
    in JSP?
    The solution I thought of is, putting the connect string into a session variable.
    Is this a could idea?
    If not, are there any other better ways of achiving this?
    Thanks for any help!
    Steven.

    Are you using Tomcat?
    Because Tomcat supports things like Application.cfm did with CF. They go in web.xml, I believe (I don't use tomcat myself).
    Your database connect (and interaction) should not be handled by individual pages. It should be in a bean, connection pooling (tomcat), JSTL, or other more scalable method (or combination of techniques that works for you). If you put it all in scriptlets, you really limit yourself later.
    I am assuming from your post that the username/pass is the same for all users. If it isn't, use a session-scoped bean to hold that info.

  • How to pass a java script variable to a JSP page

    How to assign a javascript variable value to a jsp variabe
    <script>
    var scroll="100"
    </script>
    <%
    String age=[ here i need to set the value of "scroll" ]
    %>
    is it possible ,
    thanks

    assign this scroll to a hidden field in a form
    and pass via form to server this may be one way or
    set attribute scroll and then access to server side
    may this help you
    --yogeshb                                                                                                                                                                                                                                                                                                                                                                           

  • How to use jstl variable in a jsp page

    Hi all,
    I am new to JSTL and i want to access the value of jstl in jsp.
    when i use the tag like below it is displaying the value ""
    <c:out value="${ack}"/>
    But as ack is string, i want to convert it into int. and i have written like
    <c:set var="ackvalue" value="${ack}"/>
    and int ack = Integer.parseInt(ackvalue);
    But it is showing error like varialbe can not be resolved: ackvalue
    can anybody please help me regarding this?
    Waiting for your warm response.
    Thanks in advance

    Hi,
    Thanks for your immediate reply.
    I am able to display the ackvalue when i am using
    <c:set var="ackvalue" value="${ack}"/>
    and <c:out value="${ackvalue}"/>
    But my actual requirement is to use the ack value in
    switch statement. if i can assign the value to a
    String variable, then it si easy for me to proceed.
    Please help me in this regard.
    Thanks,You can use the c:choose, c:when and c:otherwise tags
    <c:choose>
        <c:when test = "${ackvalue == 1}">
               //do stuff
        </c:when>
        <c:when test = "${ackvalue == 2}">
               //do some other stuff
        </c:when>   
       <c:otherwise>
              //stuff
        </c:otherwise>
    </c:choose>ram.

  • Updating value of a variable on a JSP page

    Hya!
    I am very new to JSP and I am struggling to make a homepage work according to the specifications my group has decided to use. I would be grateful if you could help me in this, as it's really urgent. Let me describe the issue:
    My web site contains a set of six JavaBeans that keep information that is more a less unchangeable (it works as a table). The information that is kept by the JavaBeans can be viewed by the user once he/she makes a selection. This information then will help the user in deciding to buy a certain number of tickets. That's the point where the problem appears.
    I need the variable 'totalTickets' to vary depending on each user's purchase. I've set the original value to 100 on JavaScript but that means that in each visit this number would be reset to 100 again, as JavaScript is a client-side technology. On the other hand if I set this variable in JSP the same problem would happen. Would there be a way to allow this variable to be reset after each visit? What would I need to make this possible?
    I am looking forward to hearing from all of you.
    Yours sincerely,
    Saulo

    Is this correct,
    1. User login to the system for the first time. Then TotalTicket count will be set to 100.
    2. User purchase a ticket and the count will become one less (i.e 99).
    3. For every purchase of a ticket, count will be reduced by one.
    4. User logs out. Now let us say, the count is 95. (i.e user has purchased 5 tickets).
    5. Now again user login to the syatem. The ticket count must be initialized to 95.
    and so on.
    If this is what you want, then you must either store the TicketCount in the database or atleast in the application context.
    int totalTicket=100;
    Hashtable ticketCounterMap=(Hashtable)application.getAttribute("ticketCounterMap")
    if(ticketCounterMap == null)
         ticketCounterMap = new Hashtable();
         ticketCounterMap.add("login_user_name",new Integer(totalTicket));
         application.setAttribute("ticketCounterMap");
    else
         totalTicket = ((Integer)ticketCounterMap.get("login_user_name")).intValue();
    and in case of purchasings.
    if(purchase.....)
         totalTicket--;
         ticketCounterMap.add("login_user_name",new Integer(totalTicket));
         application.setAttribute("ticketCounterMap");
    Hope this helps.
    Sudha
    P.S:- There may be errors in the above code. This is just to give you an idea.

  • Capturing xml data returned from a url post in a jsp page

    Hi,
    We are writing a interface which will capture data returned from an other website. The data returned will be in XML form.
    http://www.ecrm.staging.twii.net/ecrmfeed/ecrmfeedservices.sps?eCRMFeedInputXml=<twii><ecrmfeedinput><data%20method="Login"><username>[email protected]</username><password>password</password></data></ecrmfeedinput></twii>
    When the above url is executed in a browser, it required NT authentication. The username and password is getcouponed. Once the username and password is fed, we can see the output in the form of a xml. We require the xml in a String variable in a jsp page. We need to know the steps on how to execute the url in a jsp page. We used the url object to do the same, but we get a error saying "java.net.UnknownHostException: www.ecrm.staging.twii.net".
    Can anyone help?
    Regards,
    Gopinath.

    Hi,
    I would like to know if I can use the java.net package to get anything out of a website which requires authentication. In this case NT authentication.
    Thanks in advance,
    Gopinath.

  • How to pass applet variable to a jsp

    I just want to pass applet variable to a jsp page to access database. But how .
    Help me please.

    you can use showDocument() to show a page which could have values in the query string.
    you can use URLConnection to do GET or POST requests to a page.

  • How to use value returned from a bean in jsp page

    Hi All,
    I have a string array value being returned from a javabean to a jsp page. I want to be able to assign the value to a variable in the jsp page.
    How do I do this?
    Many thanks :)

    thanks for your response.
    I actually used something like this:
    <% String loggedin = log.User(user,password);
    out.println(loggedin);
    %>i am not yet as much of an expert on beans as i would like to be, but i thought it is not really a bean if it has a getter method which takes arguments?

  • Post parameters to a JSP from an applet

    Hello,
    Is there a way to send a post request to a JSP page from an applet ? Here is the scenario I am looking for :
    In Test.jsp, I invoke an applet. The applet should then do a POST request to the JSP. Currently, I am able to send a JSP request by appending parameters to the query string as
    getAppletContext().showDocument(new URL(getDocumentBase(),"Test.jsp?querystring")); in the applet. But this will be showing the parameters in the URL. I would like to have the parameters sent as "POST". I tried doing something like
    String data = "All URL encoded parameter names and values";
    URL postURL = new URL("Test.jsp");
    conn = (HttpURLConnection)postURL.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(data);
    wr.flush();
    wr.close();
    But how do I pass the control back to the JSP ? Any thoughts ?

    Thanks for all your responses. I posted the request and still couldn't get it working. Here is my code
    osDetection.jsp:
    <%@ page contentType="text/html; charset=UTF-8" %>
    <% // Get all the request parameters
    String userOSVersion = request.getParameter("osVersion") == null ? "" : request.getParameter("osVersion");
    String detect = request.getParameter("detect") == null ? "" : request.getParameter("detect");
    %>
    <% if(detect.equals("")) { %>
              <span>detect os version</span>
    <% } %>
    <%     if("os".equals(detect)) { %>
    <div align="center">
    <object width="250" height="75">
    <param name="type" value="application/x-java-applet" />
    <param name="code" value="Detection.class" />     
    <comment>
    <embed type="application/x-java-applet" code="Detection.class" width="1" height="2" />
    <noembed>No OS detected</noembed>
    </comment>
    </object>
    </div>     
    <% } %>
    OS Version: <%=userOSVersion%>
    Detect:          <%=detect%>
    Detection.java
    import java.applet.*;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLEncoder;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    public class Detection extends Applet {
         public void init() {
              HttpURLConnection conn = null;
              try {
                   String data = "osVersion=" + URLEncoder.encode(System.getProperty("os.version"),"UTF-8");
                   URL postURL = new URL("http://localhost:8080/detection/osDetection.jsp");
                   System.out.println("posting to the url :");
                   conn = (HttpURLConnection)postURL.openConnection();
                   conn.setRequestMethod("POST");
                   conn.setDoOutput(true);
                   System.out.println("connection open");
                   OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                   wr.write(data);
                   wr.flush();
                   wr.close();
                   // Get the response code
                   int code = conn.getResponseCode();
                   System.out.println("Response code of the object is "+code);
                   if (code==200) {
                   System.out.println("OK");
                   // Get the response
                   BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                   String line;
                   while ((line = rd.readLine()) != null) {
                   System.out.println(line);
                   rd.close();
                   conn.disconnect();
              } catch(Exception ex) {
                   System.out.println("Error:" + ex.getMessage());
    Am I missing something here ? I see the response being written to the Java console but how do I transfer the control back to JSP to do further processing in the JSP ?
    Thanks much in advance.

  • Need a fast answer... passing javascript variable to jsp page (how to use)

    This test application has 3 frames.
    I'm assigning a value "stuff" to a variable ("testfield1") in a javascript function ("getTest") that exists inside an html frame (testpage1.html)
    Then, I click on the "test submit" hypertext link to pass the value of "testfield1" to the JSP frame (testpage2.jsp) by invoking a function ("getData") in "testpage2".
    In function ("getData"), I am passing the variable "testfield1" as a parameter to the "getData" function in "testpage2".
    In "testpage2" - in the ("getData" function) I try to assign the value of the variable "testfield1" to another variable called "testfld1".
    Then, I try to extract the value of "testfld1" into a variable called "tstfld1" in a JSP scriptlet
    ....I.E. [ String tstfld1  = request.getParameter("testfld1");  ]
    But, the value is apparently not passed successfully, as tstfield1 appears to be "null".
    Can anyone explain what I'm doing incorrectly?
    The code for this test app is below...
    ********testpage0 - the parent frame*********
    <HTML>
    <HEAD>
    <TITLE>GlobalView Reports and Trending Menubar</TITLE>
    </HEAD>
    <FRAMESET FRAMEBORDER="0" ROWS="15%,85%">
    <FRAME SRC="testpage0.html" NAME="testhtmlparent">
    <FRAMESET FRAMEBORDER="0" COLS="23%,77%">
    <FRAME SRC="testpage1.html" NAME="testhtml">
    <FRAME SRC="testpage2.jsp" NAME="testjsp">
    </FRAMESET>
    </FRAMESET>
    </HTML>
    *******testpage1.html********
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <html>
         <head><title>testpage1</title>
         <link rel="stylesheet" type="text/css" href="./standard.css">
              <script LANGUAGE="JavaScript">
              parent.frames[2].location = "blank.html";
              function getTest(reportType)
                   testfield1 = "stuff";
                   alert("testpage1.html...testfield1=" + testfield1 + ", reportType=" + reportType);
                   parent.frames[2].location = "testpage2.jsp";
                   parent.frames[2].getData(testfield1);
                   return;
              </script>
         </head>
         <body bgcolor="#FFFFFF" text="#000000">
              <form name="reportRange">
                   <center>
                        <fieldset style="padding: 0.5em" name="customer_box">
                        <table cellpadding="0" cellspacing="0" border="0">
                             <tr class="drophead">
                                  <td valign="top" height="0" ><span class="drophead">
                                       test submit
                                  </td>
                             </tr>
                        </table>
                        </fieldset>
                   </center>
              </form>
         </body>
    </html>
    *******testpage2.jsp*********
    <%@ page language="java" import="java.io.*, java.util.*" errorPage="error.jsp" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <html>
         <head>
         <title>testpage2</title>
         <script language="JavaScript">
              function getData(testfield1)
                   alert("testpage2.jsp...testfield1=" + testfield1);
                   document.pageData.testfld1.value = testfield1;
                   document.pageData.submit();
         </script>
         </head>
         <body>
              <%
                   String error;
              %>
              <div id="HiddenForm">
                   <form name="pageData" method="post" action="testpage2.jsp" target="_self">
                   <input type="hidden" name="testfld1" value="0">
              </form>
              </div>
              <%
                   String tstfld1 = request.getParameter("testfld1");
              %>
              <P> testfld1 = <%= tstfld1 %> </P>
         </body>
    </html>

    parent.frames[2].getData(testfield1); is in testpage1.html
    so in the document.pageData.testfld1.value = testfield1; document = testpage1.html( not testpage2.html)
    modifying the getData to accept the document object, and refering this object to parent.frames[2].document may help you.
    good Luck ....

  • Problem accessing variables from java file to JSP page

    Hello Everyone,
    I have small problem accessing my method variables from my java bean file to a JSP page. can some please take a look and tell me why I can't populate my JSP page, I've been trying all day to get this done!!!
    This is my Java file
    package dev;
    import java.io.*;
    import java.util.*;
    public class RoundDetail2
    public String string_gameID;
    public int string_card1;
    public String readDetail_topLayer;
    public static final String SUITS[] = {" ", "Clubs", "Hearts", "Spades", "Diamonds", "Joker", "FaceDown"};
    public static final String VALUES[] = {"Joker ","Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
    public static final String SuitVALUES[] = {" ","1","2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"};
    public RoundDetail2() throws FileNotFoundException
    DataInputStream inFile=
                 new DataInputStream(
                    new BufferedInputStream(
                   new FileInputStream("C:/apps/jakarta-tomcat-4.0.6/webapps/ROOT/WEB-INF/classes/dev/Data_452SY2.txt")));
    try { 
                 while((readDetail_topLayer = inFile.readLine()) != null)
              StringTokenizer tokenizer_topLayer = new StringTokenizer(readDetail_topLayer,"\t", true);
                   while  (tokenizer_topLayer.hasMoreTokens())
                        string_gameID = tokenizer_topLayer.nextToken();
         catch(IOException e)
                    System.out.println(e.getMessage());
         Thanks KT

    ......How are you declaring the class in your JSP? ... are you instantiating it as a bean using the useBean tag, or just instantiating it in your code like normal.
    Maybe you could post the relevant JSP code too?
    Hello again,
    Only the last string is populating after the file has be tokenized. What I'll like to accomplish is passing the very first string in the file. I did not get too far in the JSP file setup because the code is still in it's testing stage, but any help will be highly appreciated.
    Here is the JSP code
    <%@page import="dev.*" %>
    <%@page session="true" language="java" import="java.io.*" %>
    <jsp:useBean id="wagerhist" scope="request" class="dev.RoundDetail2" />
    <html>
    <head>
    <title>Round Detail</title>
    <body>
      <table width="530" bordercolor="#000000" valign="top">
        <tr>
              <td align="left"  width="19%">Game ID<%=wagerhist.string_gameID%></td>
              <td align="left"  width="30%">  </td>
              <td align="left"  width="20%">card1</td>
              <td align="left"  width="31%">  </td>
            </tr>
      </table>
    </body>
    </html>

  • How to use an BPM Instance Variable in JSP page

    Hi All,
    I am using the JSP Presentation, but i don't know how to use an Instance variable in JSP page, that instance already declared in the process. And Can u explain the syntax that to include the JS file into jsp page
    Regards
    Vasu.
    Edited by bpmvasu at 04/03/2007 10:43 PM

    Hi Mariano,
    I'm using JSP presentation too. In "Interactive Component Call" active i'm using "Use JSP presentation", but i only can define one instance variable, i need to add more instance variables. In "Advanced" option of this task, i have the argument mapping .. but i don't understand how to use it.
    I have a instance variable called "genders" of the type String[Int] (Associative Array) and i'm mapping this instance variable in "Arguments Show In" option of the advanced option of JSP presentation. In JSP presentation i have the code:
    <select <f:fieldName att="person.gender"/>>
                   <c:forEach var="gender" begin="0" items="${genders}" varStatus="status">
                        <c:choose>
                             <c:when test="${person.gender == gender}">
                                  <option value="<c:out value="${gender}"/>" selected="true"><c:out value="${gender}"/></option>
                             </c:when>
                             <c:otherwise>
                                  <option value="<c:out value="${gender}"/>"><c:out value="${gender}"/></option>
                             </c:otherwise>
                        </c:choose>
                   </c:forEach>
              </select>And in my screenflow i have the code:
    genders[0] = "Male"
    genders[1] = "Female"But when i run my application, i have the error: "The task could not be successfully executed. Reason: 'java.lang.ClassCastException: java.lang.Integer'."
    What's the problem?

Maybe you are looking for