How to pass a JavaScript variable into a java method

I would like to know how to pass a JavaScript variable into a java method with in a <% %> tag inside a JSP file like so:
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<script LANGUAGE="JavaScript">
myValue = someDynamicValue;
<% System.out.println(myValue)%>
</script>
</head>
<body>
</body>
</html>
obviously "System.out.println(myValue)" will not work because myValue is seen as a java variable and not a JavaScript variable.
I would like to know how to let the jsp file, that I wrote in the above code, see myValue as a JavaScript variable and not a java variable so that I can pass it to a java method.
NOTE: the java method does not have to be a println() method, it can be any method of my choice.
NOTE: someDynamicValue is a JavaScript value that can dynamically change

I don't believe you can. JSPs are really just elaborate templates that an engine such as Tomcat parses and generates an HTML page based on. That page is then displayed to the user. By the time you want to use some function in Javascript, the JSP has already been parsed and generated.
Basically, Javascript and JSPs can't talk to each other. One's server-side and the other is client-side.

Similar Messages

  • How to pass a javascript variable to a javabean method

    Hi
    I need to pass a String from a Javascript argument to a javabean method. localUrl will be instantiated with a string not from any form item(option box, textbox, etc) so cannot use
    String param = request.getParameter("XXX").
    My code below does not work as localUrl is not seen by javaBean and returns a null.
    function ShowWaitDisplay(localUrl)
    var Description = <%=RandomFeeds.getDescription(localUrl)%>;
    //Do something with the string Description
    Thanks
    Andrew

    Since, java bean code will be executed on the server side and java script executes on client side, by the time your javascript variable created, the bean code is already been executed.

  • 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

  • How to pass table type variable into function from SQL*PLUS ?

    How to pass a table type variable from sql*plus prompt into a function ?
    Thanx in advance.

    Krishna,
    Do you mean like this?SQL> DECLARE
      2      TYPE t_tbl IS TABLE OF VARCHAR2(20);
      3      l_sample_tbl           t_tbl;
      4
      5      FUNCTION print_contents ( p_tbl IN t_tbl )
      6      RETURN VARCHAR2
      7      IS
      8          l_string            VARCHAR2(1000);
      9      BEGIN
    10          FOR i IN 1..p_tbl.COUNT LOOP
    11              IF (i = 1) THEN
    12                  l_string := p_tbl(i);
    13              ELSE
    14                  l_string := l_string || ', ' || p_tbl(i);
    15              END IF;
    16          END LOOP;
    17          RETURN (l_string);
    18      END print_contents;
    19
    20  BEGIN
    21      l_sample_tbl := t_tbl();
    22      l_sample_tbl.EXTEND;
    23      l_sample_tbl(1) := 'one';
    24      l_sample_tbl.EXTEND;
    25      l_sample_tbl(2) := 'two';
    26      l_sample_tbl.EXTEND;
    27      l_sample_tbl(3) := 'three';
    28      l_sample_tbl.EXTEND;
    29      l_sample_tbl(4) := 'four';
    30      l_sample_tbl.EXTEND;
    31      l_sample_tbl(5) := 'five';
    32      DBMS_OUTPUT.PUT_LINE(print_contents(l_sample_tbl));
    33  END;
    34  /
    one, two, three, four, five
    PL/SQL procedure successfully completed.
    SQL> HTH,
    T.

  • How to pass a javascript variable to a query in BEx?

    Hi All,
    We're using BEx SAP BW 3.x
    I'm using portal eventing to pass a variable to a BW template.  While I can pick up this value using javascript, I do not know how to pass it to the query.
    Let me just say, I am new to BEx, so any guidance you could give me would be most welcome.
    Thanks in advance,
    Liz.

    Hi,
    Perhaps this JavaScript can help?
    document.appletName.getQueryObject().setParam(1, param value);
    Call this peice of code on some event, for example the click event of a Button.
    There are many more examples on this forum, search for more.
    Regards,
    Michael

  • How to pass OSB fault variables into input payload

    Hi ,
    I am very new to OSB. as we know that OSB has some predefined variable structure like body,header, fault,inbound,outbound,..My requirement is that I want pass the fault variable elements(errorCode,reason,details..) to input payload elements. I want to see the faulted data in my payload elements which is generated by fault variables.
    Ex:-> If any validation fault occur then my payload fault variables will display errorCode---->BEA-382525, errorMessage-->Variable targeted for validate is not XML or MFL..
    Could you please help me out.I tried but i did not get the result what I expected .. Thanks in advance
    Thanks,
    Viswas

    Hi Vlad,
    I tried what you said in the Otherwise section.
    Step 1:-->This is my xQuery code:
    declare namespace ns1 = "http://www.bea.com/wli/sb/context";
    declare namespace ns0 = "http://xmlns.itc.com/emf/xsd/04/2013/v1.0/loggingService";
    declare namespace xf = "http://tempuri.org/GreetingService/xquery/faultToGreetingService/";
    declare function xf:faultToGreetingService($fault1 as element(ns1:fault))
        as element(ns0:logInfo) {
            <ns0:logInfo>
                <ns0:HeaderInfo>
                    <ns0:faultCode>{ data($fault1/ns1:errorCode) }</ns0:faultCode>
                </ns0:HeaderInfo>
            </ns0:logInfo>
    declare variable $fault1 as element(ns1:fault) external;
    xf:faultToGreetingService($fault1)
    Note: My requirement is I want pass this errorCode into ns0:faultCode which is the input element for publish action (This is publish action would call the logging Service, It is one-way process)
    Step2:-->I used a replace action-->XQuery Resource tab--> I browse the xQuery ..Here In the Variable Name section it is showing fault1 and what value we need to give in the Binding section.
              a)  If i did not provide any value it is giving the error message as "XQuery expression validation failed:XQuery error for the variable "fault1": line1,column1:                                 {err}XP0003:invalid...  "            
              b) If i provide $fault1 or $fault1/*:errorCode or $body in Binding section then the public action would not calling the logging service.
    Can anybody provide me the answer.
    Thanks,
    Viswas

  • How to pass the javascript variable value to a jsp

    Hi
    I am trying to set a javascript variable with onClick event of a radio button in jsp
    and I am assigning this variable to a hidden property in JSP whic has the corresponding getter an setter method in form.
    But I am not able to retrtieve the value assigned in either form/action .can any body help me in this:
    The code is
    <script language="javascript">
    var jais="";
         function setValue(val)
              jais=val;
         document.o.value=jais;
    </script>
         <html:hidden property="o" value=""/>
    <input type=radio name="1"
                                            value="xyz"
                                                                          onclick="setValue('XYZ')" >
                                            ABC                                        
    and in the correspoding form bean I have
    private String o_val =null;
    public String geto()
    return o_val;
    public void seto(String strs)
    o_val=strs;
    In the action I am trying to access
    by
    1)String j=((form name)form.geto();
    2)String j=request.getParameter("o")
    but with both of them I am getting the value null
    Thanks in Advance

    You need to set the value of the hidden field in your function.
    Setting an unrelated variable will not help.
    function setValue(val)
    document.forms[0].o.value = val;
    also your get/set methods should be getO() and setO().

  • How to put a javascript  variable containg the i18n key  in the i18n tag

    I have a list of values in a List box.when the user selects a praticular value.,i need to show the java script localized alert message for the selected value.
    how can i pass the javascript variable to i18n tag.
    For ex:
    function test(){
    var selectedvalue='name';
    var localizedstring='<i18n:message key="+selectedvalue+"/>';--This is not working
    alert('<i18n:message key="+selectedvalue+"/>');
    the alert message is a blank string,even though i have the key in my resource bundle.
    Also..if i give directly pass the key value to i18n string it works. like..
    var localizedstring='<i18n:message key="+name+"/>';--This is  working
    *(am passing the variable value)*

    The following should be able to pass ans.
    <script language="Javascript">
    function check_answer(ans) {
    if (testing.result.value==ans ){
    window.alert("You have got 10 marks.");
    </script>
    <body>
    <form name="testing"...>
    <%
    ResultSet rs = stmt.executeQuery("select * from level where...");
    while(rs.next())
    out.println("<tr>");
    out.println("<td>" + rs.getString("question") + "</td>");
    ans = rs.getString("answer");
    out.println("</tr>");
    out.println("<input type='text' name='result'>);
    out.println("<input type='button' value='Enter' onclick='check_answer('<%= ans%>')'>");
    %>jag

  • How to pass a file into a java method

    I am trying to pass a file into a java method so I can read the file from inside the method. How can I do this? I am confident passing int, char, arrays etc into methods as I know how to identify them in a methods signature but I have no idea how to decalre a file in a mthods signature. Any ideas please ?
    Thanks

    Hi,
    Just go thru the URL,
    http://www6.software.ibm.com/devtools/news1001/art24.htm#toc2
    I hope you will get a fair understanding of 'what is pass by reference/value'.
    You can pass Object reference as an argument.
    What Pablo Lucien had written is right. But the ideal situation is if you are not modifying the
    file in the calling method, then you can pass the String (file name) as an argument to the called method.
    Sudha

  • How to pass in a parameter into a report viewer on a jsp - and hidden

    Hi, I've built a php application and am using the java environment to enable the crystal report/viewer.  The developer was looking how to pass in a parameter into a report viewer on a jsp. Ultimately the end product we need is to get an HTML report viewer loading a report file with hidden parameters so to not expose other customer data (it's a shared database for multiple customers) preferably loaded from php using maybe the php java bridge. Would anyone happen to have any sample code or any guidance?
    <%@ page contentType="text/html; charset=UTF-8"
       pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="/crystal-tags-reportviewer.tld" prefix="crviewer"%>
    <%
    // just a test to grab rpt name from GET
    String rptFile = "report_files/" + request.getParameter("rpt");
    %>
    <crviewer:viewer reportSourceType="reportingComponent" viewerName=""
    isOwnPage="true">
       <crviewer:report reportName="<%= rptFile %>" />
    </crviewer:viewer>
    Many thanks in advance!
    Mark

    I am not aware of any html tags you can pass to the viewer for parameter values.  Normally, you would load the report in code and then use the SDK with the report object to pass parameter values.

  • How do I enter a variable into an equation?

    How do I enter a variable into an equation?

    Jacob,
    Spreadsheets don't use equations, so the usual nomenclature can be confusing.
    When you enter something into a spreadsheet cell, it is either a Literal Value (Constant), or an Expression, preceded by an equal sign, that tells the spreadsheet to display something. Every Cell Reference in the Expression is a Variable. The equal sign in this case does not signify an equality, it just signals the spreadsheet that you want it to do something, defined by the expression that follows.
    Here's an equation: A1 = B1 + C1 + 10, where B1 and C1 are variables and 10 is a constant.
    To figure out what the value of A1 is, you write an expression in cell A1. That Expression would be: =B1 + C1 + 10. The operation that is performed by the spreadsheet is that it looks at B1 and C1, adds whatever it sees there and then adds the constant 10, and displays the result in A1.
    It can get very complex. Expressions can contain Functions that catch the Time or generate a random number, or round a value, etc. Just remember that anything you see in a cell can be changed, so that content, that cell address, is a variable
    Jerry

  • How to convert an int variable into String type

    hi everybody
    i want to know how to convert an interger variable into string variable
    i have to implement a code which goes like this
    Chioce ch;
    for(int i=0;i<32;i++)
    // here i need a code to convert the int variable i into a string variable
    ch.add(String variable);
    how do i convert that int variable i into a String type variable??
    can anyone help me?

    Different methods:
    int a;
    string s=a+"";or
    String.valueOf(int) is the better option because Int.toString() generated an intermediate object to get the endresult
    Ema

  • How to pass apex item value into custom xml for chart or guage?

    Re-opening the old thread : Re: How to pass apex item value into custom xml for chart or guage?
    Which was not answered.
    Roel - Thanks. Its working - but in a semi quotes in the custom XML
    <pointers>
    <pointer value= '&P5_RUNNING_TOTAL.'
    <label enabled="true">
    <position placement_mode="ByPoint" x="50" y="15" />
    <format>{%Value}{numDecimals:1}</format>
    <background enabled="false" />
    </label>
    </pointer>
    </pointers>This question was helpful for us to resolving one recent thread : AnyChart - set Dial axis intervals dynamically?
    (Re: AnyChart - set Dial axis intervals dynamically?
    Edited by: P.Ranish on Dec 13, 2012 6:23 AM

    P.Ranish wrote:
    Is there any update for this question ???
    Edited by: P.Ranish on Dec 13, 2012 3:36 AMNo, And there won't be in the future.
    Please stop posting followup's to old threads, if you have a real problem please search the forum first and post a new question with all information
    Roel wrote:
    Try using &P5_RUNNING_TOTAL. or #P5_RUNNING_TOTAL#Just to make it clear - this will only work if page is reloaded after setting the item values dynamically via AJAX

  • How do i insert javascript stuff into dreamweaver?

    okay, first of all, im a total idiot when it comes to
    javascript and CSS, so please expect me to ask a lot of stupid
    questions.
    basically, i want to know how to insert a javascript file
    into your dreamweaver website. for example, i have a drop down menu
    i made using a program called Sothink DHTML Menu 9, and im not sure
    how to put that into dreamweaver. Can anyone help?

    Doesn't validate.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "GPaul" <[email protected]> wrote in message
    news:gnhu94$ird$[email protected]..
    > I'm not familiar with the <burp> tag?
    >
    > "Al Sparber - PVII" <[email protected]>
    wrote in message
    > news:gnhu4j$ikv$[email protected]..
    >> "name294" <[email protected]> wrote
    in message
    >> news:gnhtst$ic6$[email protected]..
    >>> okay, i just want to know if this program lets
    you customize your
    >>> drop-down
    >>> menus. from what i saw from the movie, they
    don't seem to give you the
    >>> greatest
    >>> freedom in customization.
    >>
    >> The freedom is actually total. Yes, you choose a
    style theme, but once
    >> you do the system writes a style sheet which is
    fully editable - just
    >> like a <burp> Spry style sheet </burp>
    >>
    >>> it seems like that you get a selection of
    pre-made menus and you have to
    >>> select which one you wanna use. I want to have a
    program that lets you
    >>> design
    >>> your own menu looks from imported images.
    >>>
    >>> does projectseven do that?
    >>
    >> Yes.
    >>
    >> You might want to have a look at PMM2 (which has
    replaced the one you
    >> looked at):
    >>
    http://www.projectseven.com/products/menusystems/pmm2/carbon.htm
    >>
    >> And also the tweaks section here:
    >>
    http://www.projectseven.com/products/menusystems/pmm2/tweaks/index.htm
    >>
    >>
    >> --
    >> Al Sparber - PVII
    >>
    http://www.projectseven.com
    >> The Finest Dreamweaver Menus | Galleries | Widgets
    >>
    http://www.projectseven.com/go/pop
    >> The Ultimate DW Menu System
    >>
    >>
    >>
    >>
    >>
    >>
    >
    >

  • How to pass the USER variable to RPD in 11g?

    I am trying to figure out how to pass the USER variable to the RPD in 11g.
    In 10g, I had define an intializtion block to store the USER variable and pass it to a statement that has to be executed before the query is executed.
    We use the Oracle VPD technology that allows to restrict data access. This is the statement that has to be executed before a query can run.
    select vpd_adwh.setclnvpdcontext_fnc('VALUEOF(NQ_SESSION.cuser)', UPPER(:USER))) from dual
    That is the 10g version and it works fine.
    In 11g, I tried to use
    select vpd_adwh.setclnvpdcontext_fnc('VALUEOF(NQ_SESSION.cuser)', UPPER('VALUEOF(NQ_SESSION.USER)')) from dual
    but this is not working.
    Any help?

    any ideas?

Maybe you are looking for

  • In Oracle Forms, to run all the When-Validate-Item of all the items at once

    In Oracle Forms, is there any built-in / procedure / function which is used to run all the When-Validate-Item triggers of all the Items at once ? I will put it in detail : When a form is run and while entering the data.. when we enter some data and t

  • External monitor problem after Lion upgrade

    Hi, I have a 20" iMac which has a screen resolution of 1680x1050(ATI Radeon HD 2600 Pro 256 MB).  I have been using an additional 168x1050 monitor(Dell 2009W) in dual screen mode.  This was working fine with Leopard, Snow Leopard, but it does not wor

  • Cisco ISE and ATA 188 profiling.

    I have tried to profile cisco ATA 188 adapter, based on cdp attribute; Platform: Cisco ATA 188 and assigned to a create a same identity group. I am not able to see device profiled according to identity group assigned. Instead of it its always assigne

  • ObjectHierarchicalData, Object, Array , ARGHHH :(

    Hi, I implemented ObjectHierarchicalData and wrote some functions, they work great with the source code below, private var ohd:ObjectHierarchicalData;     private var largeObject:Object =             { "id":"1", "name":"Misc", "type":"parent", "paren

  • Enhance the standard WD

    Hi experts, I have a requirement in which i have to enhance the standared WD. In the standard WD,there is a view and in that view we have one table . There is one field in the table for "Specification" and one for "Material". Once the user enter valu