Jsp variable access

How do I set and use variables in jsp,which is accessible from one jsp to the another,inspite of the jsp passing through servlet or event process handling in between each other?

can u try this ? ...
<%
page.setAttribute( "cntrE", "cntrE");
//?? maybe u wanted to do session.setAttribute( "cntrE", "cntrE");
%>
<script>
<c:choose>
<c:when test='${map.SITETYPEID == "1"}'>
cntrE = <%=(String)session.getAttribute("cntrE")%> +1
</c:when>
</c:choose>
</script>

Similar Messages

  • How can I access JSP variables from a JavaScript function in a JSP page?

    Respected sir
    How can I access JSP variables from a JavaScript function in a JSP page?
    Thanx

    You may be get some help from the code below.
    <%
        String str="str";
    %>
    <script>
        function accessVar(){
           var varStr='<%=str%>';
           alert(varStr);// here will diplay 'str'
    </script>

  • Accessing JSP variables in Included Javascript

    Hey All,
    I want to hide my javascript to be viewed on the client browser.
    I know we can do that with the javascript include ,But i am using JSP variables in
    Included javascript.I can't access those variables any more.
    Does anybody know any workarround.
    Thanx
    Vijay

    Hi Vijay,
    I am also facing the same problem of hiding javascript in the client browser. My javascript variables are getting initialised on the fly using JSP. Since JSP is compiled on the server side, one can't compile .js file on the client side.
    What u can do is to divide your page into frames with
    <frameset rows="100%,0%">. Now put your form hidden fields or the .js file in frame 2 which is not visible to the user and then assign your jsp variables in the frame2 html/jsp page. Now access your variables from frame2 in frame1 using
    var i = parent.frames[1].document.forms[0].elements[0].value
    Assuming that there is 1 form and 1 hidden field in frame2 html/jsp page.
    I hope u get the logic rite....
    I had done it for application but problem is that our users are real MORONS and they keep doing ctrl+F5 which takes them to the Indexpage.
    If you get some other solution then please mail it to my email address
    [email protected]
    Regards
    Vimlesh

  • Can JavaScript access JSP variable?

    Could we do this? Or, how could we have JavaScript access JSP variable?
    <%
    String fooBar = request.getParameter(......
    %>
    <script language="JavaScript">
    <!--
    if (fooBar  == ...) {
    -->
    </script>

    To access the variable in Javascript you'll have to
    write it out from the JSP. You'll need to do something
    like:
    <%
    String fooBar = request.getParameter(......
    %>
    <script language="JavaScript">
    <!--
    var fooBar = '<%=encodeQuotes(fooBar)%>';
    if (fooBar  == ...) {
    -->
    </script>You'll need to either make sure fooBar doesn't contain
    any quotes or write a function to replace each ' with
    \'.Thanks!
    That works perfectly, without encodeQuote() method in my current case.
    Thanks again. You ar a saviour.

  • Assigning html input value to a jsp variable

    I have the following problem: I need to assign the value of html <input> field to a jsp variable. This should be done without submittion of the form.
    <form name="main">
    <table>
    <tr>
    <td><input type="text" name="gantry" value="123"></td>
    </tr>
    <table>
    </form>
    Is there any way to access main.gantry.value from jsp and assign it to a variable? I tried
    <% prevGantry = main.gantry.value; %>
    but it didn't work, and the problem is not with parsong or initialisation. Please, can anyone help?
    Best regards, SoVa.

    No it can't be done. You are mixing up java with javascript.
    Java/JSP runs on the server end. Generates an HTML page and stops running.
    The page loads in the browser, and and can run javascript locally.
    The only way to run java code again is to go through the request/response process. ie submit a form, click a link, make an Ajax call...
    The only way to get a field from the screen into a java variable is via request.getParameter().

  • Using jsp variable in java code

    Hey guys,
    I need some help hope you guys can help me.
    I've declared a variable "error" in a jsp. how do I access this variable in the java code whice resides in the same jsp page.
    I know I can use java variable in jsp code using
    <%= sVariable %>
    where sVariable was declared in the java code. but how do I access a jsp variable in java code??
    Thanks very much in advance

    Thanks for the reply.
    This is what I want to do.
    I've declared a variable "error" using <c:catch var="error">I want to check the value of this variable and suppose if it contains XYZ (error variable will have a long string so I just want to check if it contains a specific value) I want to do step1 and if the variable of error is not XYZ I want to do step 2
    Problem is I dont know how to check if error contains the XYZ in jsp thats why I thought java code would help here.
    Can you guys suggest a better way to solve my problem.
    Thanks again

  • Assigning a javascript value to a JSP variable

    How do i assign a javascript value to a JSP variable?
    eg
    <%
    String JSPvar;
    %>
    <script language="JavaScript1.2">
    <!--
    var javascriptVar="hey"
    -->
    </script>
    <%
    JSPvar = javascriptVar ???
    %>

    You do know that the JSP runs on the server and generates HTML, including Javascript, that is executed on the client, don't you?

  • Help: How to assign dynamically a javascript variable to a jsp variable???

    Hello all,
    What I need to do is to assign the value of the html form element which is a checkbox in this case:
    <input name="ADB02_checkbox" type=checkbox id="ADB02_checkbox" onClick="decide_enable_or_disable_particular_checkbox()" value="ADB02">
    to a jsp variable :
    <%
    String riderCode = "";
    %>
    Its dynamic because i need to do different operations based on different rider codes like in this function:
    function decide_enable_or_disable_particular_checkbox() {
    var rider = document.rider_form;
    alert(rider.ADB02_checkbox.value);
    if (rider.<%= riderCode%>_checkbox.checked == true) {
    enable_all_row_elements_for_<%= riderCode%>();
    else {
         disable_all_row_elements();
    which uses the naming of the rider code to call other corresponding functions.
    so is there any way that you guys ca suggest a solution.
    what i thought is to do this:
    function decide_enable_or_disable_particular_checkbox() {
    var rider = document.rider_form;
    HERE--> riderCode = rider.ADB02_checkbox.value;
    alert(rider.ADB02_checkbox.value);
    if (rider.<%= riderCode%>_checkbox.checked == true) {
    enable_all_row_elements_for_<%= riderCode%>();
    else {
         disable_all_row_elements();
    or
    add an onFocus="riderCode = document.rider_form.ADB02_checkbox.value;" in the checkbox tag.
    but can i do that or is there any other way or is it totally impossible to assign javascript values to jsp variables.

    Hi again,
    I got a problem here abt looping in javascript.
    The prob is that only the 1st loop works the rest are not.
    So only the checkbox in the 1st row is enabled, the rest aren't.(only ADB02 is enabled not DLP01 cause ADB02 is 1st in the loop)
    Here are 2 of many of the checkboxes in different rows:
    <input name="ADB02_checkbox" type="checkbox" id="ADB02_checkbox" value="checkbox" onClick="val_checkbox()" disabled=true>
    <input name="DLP01_checkbox" type="checkbox" id="DLP01_checkbox" value="checkbox" onClick="val_checkbox()" disabled=true>
    This is declared in jsp:
    <%
    //to be used with javascript function prepare_elements() for checking to enable/disable checkbox , to check age base and limit of insured
    String[][] riderCheckArray = {
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_ACCIDENTAL_DEATH_BENEFIT, "20", "60"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_LIFELINE_BENEFIT, "20", "50"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_MEDICASH_100_PLAN, "0", "55"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_MEDICASH_200_PLAN, "0", "55"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_MEDICASH_300_PLAN, "0", "55"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_MANUTERM_REDUCING_TERM_ASSURANCE_PLAN, "16", "65"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_PERSONAL_ACCIDENT_BENEFIT, "20", "65"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_15_YEAR_LEVEL_AND_CONVERTIBLE_MANUTERM_RIDER, "16", "55"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_20_YEAR_LEVEL_AND_CONVERTIBLE_MANUTERM_RIDER, "16", "50"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_5_YEAR_RENEWABLE_AND_CONVERTIBLE_MANUTERM_RIDER, "16", "60"},
    {allPlans.PLAN_HER_MY_FUTURE, allRiders.RIDER_10_YEAR_RENEWABLE_AND_CONVERTIBLE_MANUTERM_RIDER, "16", "60"},
    %>
    Here's the script (the riderCheckArray[any no.] should be eg: riderCheckArray[0] (has an i in front))
    <script>
    <!--////////////////////////////////////PREPARE PAGE BASED ON PLAN///////////////////////////////////-->
    function prepare_elements() {
    var rider = document.rider_form;
    <!--///////////////////////////////////////////////////for her@myfuture////////////////////////////////////-->
    for (i=0 ; i < <%= riderCheckArray.length%> ; i++) {
    if ("<%= txtPlanCode%>" == "<%= riderCheckArray[i][0]%>" ) {
    riderCode = "<%= riderCheckArray[i][1]%>";
    if (<%= insuredAge.intValue()%> < <%= Integer.parseInt(riderCheckArray[i][2])%> ||
    <%= insuredAge.intValue()%> > <%= Integer.parseInt(riderCheckArray[i][3])%>) {
    disable_particular_checkbox();
    alert("This rider cannot be attached. This rider can only be attached for age range " +
    <%= riderCheckArray[i][2]%> +
    " to " +
    <%= riderCheckArray[i][3]%>);                    
    else {                    
    enable_particular_checkbox();
    <!--////////////////////////////////////ENABLE/DISABLE checkboxes////////////////////////////-->
    function enable_particular_checkbox() {
    var Rdr_Checkbox = riderCode + "_checkbox";
    var rider = document.rider_form;
    rider.all(Rdr_Checkbox).disabled = false;
    rider.all(Rdr_Checkbox).style.background ="FFFFFF";
    function disable_particular_checkbox() {
    var Rdr_Checkbox = riderCode + "_checkbox";
    var rider = document.rider_form;
    rider.all(Rdr_Checkbox).disabled = true;
    rider.all(Rdr_Checkbox).style.background ="CCCCCC";
    </script>

  • How to assign a JSP variabl's value to a JavaScript variable?

    Hello,
    I want to assign a JSP variable's value to JAVASCRIPT variable.
    or how to assign JavaScript variable's value to JSP varialbe
    HOw do i do it ?
    can anyone please help?
    Regards and thanks for your time.
    Ashvini

    I want to assign a JSP variable's value to
    JAVASCRIPT variable.
    var jsVariable = <%=someVariable%>;
    or how to assign JavaScript variable's value to JSP
    varialbeYou can't. JSP is server-side and JavaScript is client-side. The JSP variables are never available on the client side for any sort of assignment.

  • Assining a bean attribute to a jsp variable

    I am writing a struts application and am using
    <bean:write name="configattribute" property="name"/>
    to print out info on my jsp page.
    I was wondering if I could assign that value to a local jsp variable so I can check its value and change the colour of the text accordingly.
    e.g.
    String name = <bean:write name="configattribute" property="name"/>;
    if name.equals("Ben"){
    out.print(<font color=\"red\">;
    else{
    out.print(<font color=\"blue\">;
    }

    You should still be able to use the code I listed...the logic:iterate tag creates the bean "configname" in the page scope. So you should be able to do something like this:
    <logic:iterate id="configname" name="confignames">
       <tr>
          <td>
    <% ConfigName configname = (ConfigName)pageContext.getAttribute( "configname" );
       String color = "blue";
       if( "julius".equalsIgnoreCase( configName.getOwner( ) ) )
          color = "red";
       } %>
            <span style="color: <%= color %>"><bean:write name="configname" property="owner"/></span>
          </td>
          <td>
             <bean:write name="configname" property="name"/>
          </td>
       </tr>
    </logic:iterate>Does that sound right?
    - Jesse

  • Unable assign a BPM Object field value to a JSP Variable using "invoke"

    Hi,
    I'm unable to retrieve a value returned by a BPM Object Method and use it in JSP. Here is what I'm trying to achieve:
    BPM object named : "myObject" has a method "getRequiredValue" which returns a "String". I want to assign the value returned by "getRequiredValue" to a JSP Variable "myVariable" using invoke method as below:
    <% String myVariable = ""; %>
    <f:invoke var="${myObject}" methodName="getRequiredValue" retAttName="myVariable"/>
    <% out.println ("myVariable: " + myVariable); %>
    When I execute the above code I don't get the value being returned by "getRequiredValue" into "myVariable".
    Any help would be highly appreciated!
    regards,
    MK

    1. Make sure you mark the "Server Side Method" property of the getRequiredValue method to "Yes".
    2. I guess you dont need to specify "<% String myVariable = ""; %>". Try removing it.
    3. Replace "<% out.println ("myVariable: " + myVariable); %>" by <c:out value="${myVariable}"/> just in case!
    4. Lastly, I hope "myObject" is the name of the instance variable in your screenflow, and not the BPM object name.
    Hope this helps
    -Hemant

  • How to get javascript variable in jsp variable

    Hi all,
    i have a variable str in my javascript function
    var str = somevaluei want this str value in jsp variable in the same page...
    how can this be done..???
    any ideas...
    Thanks

    I dont know if its possible or not.
    Actually it depends on what do you want to do with the variable.
    as far as assisginng value to the hidden variable is concerned it can be done this way.
    <% jsp code
    String hiddenVar = "";
    %>
    < html code
    <input type type = "hidden" name="hidden" vale="<%=hiddenVar %>"
    html ends>
    while in js function you can assign vale to the hidden variable which will ultimately assign value to the JSP variable as follows.
    var str = "value";
    document.form_name.hidden_field_name.value = str.
    hope this hepls.

  • How can I obtain the value of a database column in a JSP variable ?

    How can I obtain the value of a table column in a JSP variable?
    For example the <jbo:ShowValue datasource="cl" dataitem="Cont" ></jbo:ShowValue>
    I need to have it in a variable like this:
    <% String cnt=<jbo:ShowValue datasource="cl" dataitem="Cont" ></jbo:ShowValue>; %>
    But it is not workig this way.
    Please help me to obtain the value.
    I am using JDev RC2.
    Thanks.

    Try something like
    String cnt = c1.getRowSet().getCurrentRow().getAttribute("Cont").toString();
    -A
    How can I obtain the value of a table column in a JSP variable?
    For example the <jbo:ShowValue datasource="cl" dataitem="Cont" ></jbo:ShowValue>
    I need to have it in a variable like this:
    <% String cnt=<jbo:ShowValue datasource="cl" dataitem="Cont" ></jbo:ShowValue>; %>
    But it is not workig this way.
    Please help me to obtain the value.
    I am using JDev RC2.
    Thanks.

  • How to pass a jsp variable into javascript??

    <p><%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
    <p><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
    <p><html>
    <p><c:set var="binrmapi" value="http://localhost/paas-api/bingorooms.action;jsessionid=XXXXXX?userId=TEST2&sessionId=1&key=1" />
    <p><c:import var="testbinrm" url="${fn:replace(binrmapi, 'XXXXXX', jsessionid)}"/>
    <p><c:set var="tuples" value="${fn:split(testbinrm, '><')}" />
    <p>Time until next game
    <p><c:forEach var="tuple" items="${tuples}">
    <p><c:if test="${fn:contains(tuple, 'row ')}">
    <p> <p><code>
    <p> <c:set var="values" value="${fn:split(tuple, '=\"')}" />
    <p> <font color="blue">
    <p> <c:out value="${values[17]}" />
    <p><c:set var="remainingtime" value="${values[17]}" />
    <p> </font>
    <p> </code>
    <p></c:if>
    <p></c:forEach>
    <p><form name="counter"><input type="text" size="8" name="d2"></form>
    <p><script>
    <p>var milisec=0
    <p>var seconds=eval("document.myForm.remaining").value;
    <p>function display(){
    <p> if (milisec<=0){
    <p> milisec=9
    <p> seconds-=1
    <p>}
    <p>if (seconds<=-1){
    <p> milisec=0
    <p> seconds+=1
    <p> }
    <br>else
    <p> milisec-=1
    <p> document.counter.d2.value=seconds+"."+milisec
    setTimeout("display()",100)
    <p>}
    <p>display()
    <p></script>
    <p></body>
    <p></html>
    <p>This is my code that i was working on, in the jsp part of the script, i get a api call and save a value of time in the variable remainingtime.. and in the javascript, i try to have a countdown clock counting down the remaining time.. but i guess it doesnt work.. how can i get that working? thanks alot
    Message was edited by:
    hamham3001
    Message was edited by:
    hamham3001
    Message was edited by:
    hamham3001
    Message was edited by:
    hamham3001

    Re: How to pass a jsp variable into javascript??Here is the sameple one, hope it will solves your problem.
    <html>
    <body>
    <form name=f>
    <%!
    String str = "A String"
    %>
    <script>
    var avariable = <%=str%>
    <script>
    </form>
    </body>
    </html>
    Let me know if you face any problem

  • Is it possible for an applet within a jsp to access a server session?

    I was trying to find info (and sample code) where an applet that is embedded and running within a JSP page accesses the same session of the jsp page it is in.
    The need is for the the applet to access a string within the session and capture it's value and then perform some actions with the string client side within the applet. The value of the string is not important for the example, just being able to access it is.
    Also can javascript cause the applet to call the server on say an "onclick" event? If so, how is this done?
    In otherwords, can javascript interact with an applet?

    Check out the documentation on Heterogeneous Connectivity.
    Hope this helps!

Maybe you are looking for