Assigning a JSTL variable to a ariable in scriptlet

Hi
how do i assign a JSTL to a variable in Scriptlet?
Regards
Abhinav

You can do this:
<% request.setAttribute("x", "hello"); %>
<c:out value="${x}"/>or if you want to go from JSTL to scriplet you can:
<c:set var="testvar" value="hello" scope="request"/>
<%= request.getAttribute("testvar") %>Both of these will output "hello"
<c:set> defaults to the page scope, so you could substitute pageContext for request and get the same results (remove scope="request" first though).
Karl

Similar Messages

  • Assigning a jstl variable to java Script variable

    Hai All,
    I created one jsp page with java script with JSTL.
    I retrive arrayList from simple java bean in jsp page with help of JSTL .
    Now i want assign the ArrayList value through JSTL to Java Script Array.
    How to convert JSTL to Java Script.
    Please give me details asp.
    thanks ,
    Bala

    You can do this:
    <% request.setAttribute("x", "hello"); %>
    <c:out value="${x}"/>or if you want to go from JSTL to scriplet you can:
    <c:set var="testvar" value="hello" scope="request"/>
    <%= request.getAttribute("testvar") %>Both of these will output "hello"
    <c:set> defaults to the page scope, so you could substitute pageContext for request and get the same results (remove scope="request" first though).
    Karl

  • 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?)

  • Assign a Javascript variable value to a ABAP variable

    Hi,
       I wish to assign a javascript variable value to  a ABAP variable. Any ideas how to do that?
        Many thanks.
    Rgds,
    Bernice

    Here's another suggestion for you.
    BSP Application: SBSPEXT_HTMLB
    Check out the radionbuttongroup.bsp
    So then instead of using a standard HTML radio buttons you can use the HTMLB element with the parameter for onClick set then in your DO_HANDLE_EVENT you can read the value.
    VIEW
    <htmlb:radioButtonGroup id="radio">
      <htmlb:radioButton id="id_link"
                       text="Link"
                    onClick="myClickHandler"/>
      <htmlb:radioButton id="id_unlink"
                       text="Unlink"
                    onClick="myClickHandler"/>
    </htmlb:radioButtonGroup>
    DO_HANDLE_EVENT
      DATA:   lt_event        TYPE REF TO if_htmlb_data.
      lt_event = cl_htmlb_manager=>get_event_ex( request ).
      if lt_event IS NOT INITIAL.
        if  lt_event->event_name = htmlb_events=>radiobutton.
           case lt_event->event_id.
            when 'control_id_link'.
              schalter = ' '..
            when 'control_id_unlink'.
              schalter = '1'.
           endcase.
        endif.
      endif.
    There is an example of how to use it and read it in the DO_HANDLE_EVENT you then just have to pass the variable around (in this example the variable name is schalter and is defined as char1 in the class)

  • Assigning Value to Variable in Sapscript

    Hi,
    To initialized value of the variable when I tried to assign 0 to variable (like in the following statement) it comes up with error 'Command Expected'.
    &RF140-ZALBT&= '0'.
    Please let me know where and what I am doing wrong in assigning value to a variable?
    Regards,
    Shabbar

    Hi,
    Still its not working. The statement I am writing is
    /: &NET& = &RF140-WRSHB& - &RF140-MSATZ&
    but the system gives error on that.
    NET is the local variable declared with Define statement and both the others are defined in print program.
    Even I tried
    /: &RF140-ZALBT& = &RF140-WRSHB& - &RF140-MSATZ&
    but still the same error.
    Any comments?
    Regards,
    Shabbar

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

  • How to assign a Substitution variable dynamically?

    Hi All,
    I was trying to assign a substitution variable which should get data from the time period and should directly load into the substitution variable automatically.
    The process should be automated. so as to refrsh the substitution variable daily.
    Any comments are highly appreciated
    With Regrads
    Prads

    Sorry for the double-post, I didn't quite get that you wanted to read the Time Period dimension.
    Is that what you are trying to do? Get a list of the periods (usually these are pretty well known) and then find the latest one for a given member combination that has data and then set a substitution variable off of that?
    You can run reports (or DATAEXPORT calc command) to get data from MaxL.
    Or are you trying to do something else?
    Regards,
    Cameron Lackpour

  • Accessing a JSTL variable in a JSP Scriptlet (need to replace string )

    I have
    <c:set var="myVar" value="..." />
    I need to replace single quotes and double quotes to be escaped because I pass them into javascript functions and set them as ID for div sections
    ... onclick ="func('${myVar}')" ..
    <div id="${myVar}">
    but if the string contains ' single quotes it messes up the javascript or double quotes messes up the ID portion of the HTML tag
    I know there is the JSTL function fn but I can't figure out how to do it properly in JSTL
    <c:set var="myVar"
    value="${fn:replace(myVar, "'", "\"")"/>
    But that gets tricky since the value portion is enclosed in quotes
    So I was thinking of using a Scriptlet part instead.

A: Accessing a JSTL variable in a JSP Scriptlet (need to replace string )

escaping quotes within quotes within quotes.... ARGH!
Recipe for a headache if ever there was one.
However you must be strong and resist the temptations of the dark side (Scriptlet code)
My suggestion for cleaning this up - write your own static function for escaping javascript strings.
public static String escapeJavascriptString(String s){
  return .......
}Then define the function in a tld:
<function>
    <description>
      Escapes a string for javascript purposes
    </description>
    <name>escapeJavascript</name>
    <function-class>com.mypackage.ELFunctions</function-class>
    <function-signature>java.lang.String escapeJavascript(java.lang.String)</function-signature>
    <example>
      <c:out value="${myfunc:escapeJavascript(name)}">
    </example>
  </function>Cheers,
evnafets

escaping quotes within quotes within quotes.... ARGH!
Recipe for a headache if ever there was one.
However you must be strong and resist the temptations of the dark side (Scriptlet code)
My suggestion for cleaning this up - write your own static function for escaping javascript strings.
public static String escapeJavascriptString(String s){
  return .......
}Then define the function in a tld:
<function>
    <description>
      Escapes a string for javascript purposes
    </description>
    <name>escapeJavascript</name>
    <function-class>com.mypackage.ELFunctions</function-class>
    <function-signature>java.lang.String escapeJavascript(java.lang.String)</function-signature>
    <example>
      <c:out value="${myfunc:escapeJavascript(name)}">
    </example>
  </function>Cheers,
evnafets

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

  • I need in Formula Node to assign to the variable value 4000000000!!! What kind of variable it should be???

    i've just tryed to write unsigned in32, but it does not understand 'unsogned'... But i need variable to be unsigned, because the max value = 4000000000... So, how can i solve this probleme???

    Hi,
    I don't see exactly what you're trying to do here.
    Where do you want to assign the variable 4000000000 to? If you want it as an
    input, just use a dbl, with only zeros behind the coma.
    Note that an integer is a number without any decimals. An integer in LabVIEW
    is this, but with an extra limitation that it can only be 32 bits... So a
    dbl can be an integer.
    If the input dbl is not an integer, use round, round to -inf or round to
    +inf to make it one. This can also be done if the output needs to be an
    integer.Inside the formula node floor(x), int(x), intrz(x) or ceil(x) can be
    used to make integers.
    I hope this is what you mean... I can't see any problems doing this.
    Regards,
    Wiebe.
    "DrON" wrote in message
    news:506500000008000000E
    [email protected]..
    > I need in Formula Node to assign to the variable value 4000000000!!!
    > What kind of variable it should be???
    >
    > i've just tryed to write unsigned in32, but it does not understand
    > 'unsogned'... But i need variable to be unsigned, because the max
    > value = 4000000000... So, how can i solve this probleme???

  • [SOLVED]assigning "special" shell [variable] to awk, got problem

    $ VAR='AB' ; echo "$VAR" | awk -v foo="$VAR" '{gsub(foo,"Z");print}' # [1]
    Z
    $ VAR='[AB]' ; echo "$VAR" | awk -v foo="$VAR" '{gsub(foo,"Z");print}' # [2]
    [ZZ]
    $ VAR='[AB' ; echo "$VAR" | awk -v foo="$VAR" '{gsub(foo,"Z");print}' # [3]
    awk: (FILENAME=- FNR=1) fatal: Unmatched [ or [^: /[AB/
    $ VAR='AB]' ; echo "$VAR" | awk -v foo="$VAR" '{gsub(foo,"Z");print}' # [4]
    Z
    Just read about this:
    Regular Expression Operators @ The GAWK Manual wrote:
        This is called a character set. It matches any one of the characters that are enclosed in the square brackets. For example:
        [MVX]
        matches any of the characters `M', `V', or `X' in a string.
    And I tried,
    $ echo "[AB]" | awk '{gsub(/\[AB\]/,"Z");print}' #[5]
    Z
    $ echo "[AB]" | awk '{gsub(/[AB]/,"Z");print}' #[6]
    [ZZ]
    [2] is behaving like [6] when I actually want it to be acting like [5].
    What syntax should I use?
    Last edited by lolilolicon (2009-08-16 10:58:28)

    fumbles, I'm sorry I didn't explain myself clearly.
    $ VAR='[AB]' ; echo "$VAR" | awk -v foo="$VAR" '{gsub(foo,"Z");print}'
    outputs:
    [ZZ] --> awk replaces each of A and B with Z, and left '[]' intact.
    What I want is:
    Z --> awk treats '[AB]' as a whole normal input, just like 'ABCD' or whatever...
    Just like what I said, "[2] is behaving like [6] when I actually want it to be acting like [5]."
    I need to do this because I'm writing a script where shell variable is assigned to awk variable, which contains '[]'. Like you said, awk is treating it as part of a regular expression...
    EDIT:
    Ok, an ugly solution::
    $ VAR='[AB]'
    $ VAR=$(echo "$VAR" | sed 's/\[/\\\\\[/;s/\]/\\\\\]/') #now VAR='\\[AB\\]'
    $ echo "[AB]" | awk -v foo="$VAR" '{gsub(foo,"Z");print}'
    Z
    This almost sovles the problem I encountered in the script.
    But there should be a better answer!
    Say, is there a way to turn off awk's regular expression? --> Just found out grep's -F option. How about awk??
    Last edited by lolilolicon (2009-08-16 08:42:36)

  • JSTL variables

    Hello All,
    Need help , I'm new to JSTL. My page works fine on my local machine.
    I uploaded it to a hosting site
    and the JSTL variables show instead of it's content.
    for example, I see on the page :
    ${cfList.ClientID} ${cfList.LName} ${cfList.Address}
    instead of the content of ClientID,LName and Address
    I have jstl.jar and standard.jar in the directory /public_html/WEB-INF/lib/
    Please Help what could be the cause for this.

    Maybe you have to ensure you are running such a container before you worry about where you put the files. You've got it back to front.

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

  • How to assign java script variable to a hidden parameter in JSP?

    Hi All,
    I want to assign the variable in the Jscript to a hidden parameter in JSP page.
    <select name="sortingOption" class="sortingOptions" onchange="changeSortOption(this)">
    <c:forEach var="sortingOption" items="${sortingOptionList}">
    <c:set var="sortingOptionValue" value="${sortingOption}" target="java.lang.String"/>
    <c:choose>
    <c:when test="${sortingOptionValue == sortingOptionValueFromRequest}">
    <option value="${sortingOptionValue}" selected="selected">${sortingOptionValue}</option>
    <input type="hidden" name="srchType" value="none"/>
    </c:when>
    <c:otherwise>
    <option value="${sortingOptionValue}">${sortingOptionValue}</option>
    </c:otherwise>
    </c:choose>
    </c:forEach>
    </select>
    In changeSortOption script,they capture the value selected by the user and then they submit the form.I want to assign that value to a hidden parameter in JSP,can someone tell me how to do that?
    I dont have the Jscript code with me right now to post here.

    To the point: just by accessing/manipulating the HTML DOM using JS. Learn JS and HTML DOM. There are basic tutorials at w3schools.com. Besides, your code syntax is still invalid. The input hidden elemend doesn't belong in a select element. Learn HTML. There's a basic tutorial at w3schools.com as well.
    For future HTML/JS problems please consult the appropriate forums. This has not much to do with JSP. There are ones at webdeveloper.com.

  • Using a backing bean in JDeveloper to assign bean class variables

    I am using JDeveloper 10 to make a jsp page that is a form full of inputs and buttons. JDeveloper then creates the setters and getters for you for the ids of the various inputs and buttons. I also have used JDeveloper to create a backing bean.
    The idea of this is to have the backing bean read in parameter(s) from an http source/link(when the form is loaded or instantiated) and assign those parameter(s) to one of the bean class local variables.
    The reason i want to do this is, is that when the form is loaded the first thing it will do is open up an available database(in the bean class constructor), then in the constructor call a function to do a database query that will return a result set that will then be used to fill up the form.
    That variable that is assigned by the backing bean will be the value of a unique database identifier for doing the sql query so that is why it is important that i get this value as the form loads.
    So simply i need to find out from someone how to do this. i am totally new to doing any jsp development or using managed beans and i have gotten far enough to launch the form, retrieve and write to the database using sql queries and all the rest.
    I just dont know enough about managed beans to make a decision on things like making the bean have a session scope. do i need request scope? if i change to request scope how do i make sure the database isn't being called every time the page changes or is refreshed?(when i had it as request scope the constructor was being called every time the page was reloaded and that isnt effecient at all, especially with multiple users). can you define more than one managed bean in one faces config file? do i have to manually change something in the jsp file to make sure things run smoothly?
    Just maybe things are easier than i see them to be and my only problem is that i just dont understand what i am doing. here is what my backing bean looks like now with just basic session scope.
    An example of course would be something like: http://host:port/context-root/faces/register.jsp?12345 - where 12345 would be the value that i would like to assign to a local variable in my bean class that can then be used for filtering out information via a query then filling up the form, all this happening at instantiation.
    <?xml version="1.0" encoding="windows-1252"?>
    <!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config xmlns="http://java.sun.com/JSF/Configuration">
    <managed-bean>
    <managed-bean-name>beanpackage</managed-bean-name>
    <managed-bean-class>beanpackage.beanclass</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <!--oracle-jdev-comment:managed-bean-jsp-link:1register.jsp-->
    </managed-bean>
    </faces-config>
    This is what i have now, i've tried tons of stuff on the web like assigned value parameters but just am stuck on exactly what to do as nothing has seemed to work. Any help would be appreciated. Thanks in advance!

    Hi,
    don't think you will get a readily programmed solution to this (though I wish you luck). Here's how I would approach the managed bean issue
    - One managed bean that you configure from a java.util.HashMap. This bean should be in requestScope (should be okay here). Say the bean is called "formFields", then adding data to it can be done with the following EL #{formBean['attribute_name']}. You need to add this as the value Expression of the inputText field you create dynamically. The filed will then read and write to the HashMap
    - Create a managed bean in session scope to handle the database interaction. Put this into session scope (e.g. "database")
    - Create a managed bean that holds the action listener that handles the update, insert and delete actions (e.g. logic handler). This bean has a JSF reference to the root component in the page (or the form layout component to add the fields to)
    The "database" bean is referenced from the logic handler managed bean using the #{database} expression, which you resolve using a ValueBinding (ExpressionBinding in JSF 1.2). Or, you configure the bean as a managed property.
    The logic managed bean also needs to reference the formFields bean (similar to above) to access the contained filed names and attributes. If the filed attributes match column names in the database then you should be all set
    Frank

  • Maybe you are looking for

    • Windows XP mode/ Windows virtual PC

      I have to support some LV7.1 programs (along with newer versions).  I just bought a new laptop with Windows 7 Home 64-bit.  LV7.1 loads and runs, but the drivers disk pukes on the 64-bit OS.  (This was not unexpected...) The new PC does have an Intel

    • SSRS reports are not printing probably

      when I preview my reports they look great but when I print them I get some blank pages

    • Firefox will not launch

      firefox will not launch after upgrading. Every time I try to launch I am advised to reboot to complete the upgrade.

    • IDOC types by Function Module

      Hello, I would like to find the IDOC types available by function module.  For example, all idoc types for Production Planning module.  Is there an easy way to get that info? Thanks

    • Can you reinstall a CC app after it has been uninstalled on a PC?

      I installed the updated version of InDesign CC (2014) onto my work PC. The next day my computer was having trouble starting and running slow. IT suggested that I uninstall the updated InDesign (2014) so I did, plus the previous version CC, so I would