Passing struts-tag value to java / javascript variable in JSP

Hello all,
Im trying to pass the value got from the struts-tag to the java variable in the Jsp. However Im not able to get the o/p. Can u guys help me on this pls...
<logic:notEmpty name="TreeBean" property="list">
    <logic:iterate id="Type" name="TreeBean" property="list" indexId="i">
     <br/><bean:write name="Type" />
    </logic:iterate>
</logic:notEmpty>Here the list can be populated in the jsp page. However i want the values into jsp list. Im not able to populate the same..
<% List jspList = null;
%> I want the values into the jspList variable for further processing. Can u guz pls help me on this....

Which do you want it in?
A java variable for use in <% scriptlet code %> or a javascript variable for use on the client end?
scriptlet:
<jsp:useBean id="TreeBean" type="java.util.List" class="java.util.ArrayList" scope="?????" />
Having scriptlet code on the page is considered bad coding style.
What is it you are trying to accomplish by making the value accessible?
What are you trying to do in java / javascript that can't be done with JSP tags?

Similar Messages

  • I want to assign the value of a Javascript variable to JSP Variable

    I want to assign the value of a Javascript variable to JSP Variable .. for example :
    <%
    Bla Bla Bla
    %>
    <script>
    var JavaScriptVariable="hello"
    </script>
    <%
    String JSPVariable=// The Value of JavaScriptVariable ;
    %>
    How can i do that ??
    Thanks

    >I want to assign the value of a Javascript variable to JSP Variable
    cannot be done.Friend try to understand concepts properly Javascript is always excuted by the browser @clientside where as JSPCode is executed Websever(ServletContainer) @serverside.Through you are combining JSP Code blocks(Tags,Expressions,scriptlets...) & javascript under a single page webserver can only identify what is their under JSP Code blocks.
    Hope this could be an appropriate answer for your question.
    However,you can as well submit a request by encoding your URL with request parameters and the submit to the page and then collect it using request.getParameter(name).
    But under a single context state it is not possible
    REGARDS,
    RaHuL

  • Assigning values to a javascript variable

    Hi,
    Using request dispatcher, i'm forwarding the control to a html from a servlet like this(obj.forward(/index.html?field1=value1&field2=value2).
    In the receiving end, ie., in the html i would like to assign those 2 field1,field2 values to a javascript variables. Javascript located in the index.html.
    I don't know how to do this.
    Pls any one help me to get of this pblm
    Thanks in Advance
    Kannan.T

    Hi thanks for ur reply,
    You r telling while forwarding a request from one
    servlet to another servlet, we can't add query
    string(requestparameters). But then how come this
    code is working?
    RequestDispatcher
    rdis=getServletContext().getRequestDispatcher("/MyServ
    let?type=normal");
    rdis.forward(req,res);Well I owe an apology here - I was not completely correct. I have tested and found that you can indeed add parameters that way. The catch is that these parameters are nested to that forwarded /included resource. It is not available in the original jsp or to some other resource included from the original jsp unless ofcourse you add the parameter again.
    >
    please give me a solution.
    Like this i have to forward my request (with
    querystring) to a html page.
    That htmlpage should receive parameters and assign
    the values to a javascript variables.
    how can i achieve this.
    thanks in advance.My original reply stands.
    You cannot do that in a html page. You have to have a jsp that generates the html.
    ram.

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

  • How can I assign javascript variables to jsp or java variables.?

    How can I assign javascript variables to jsp or java variables.?

    See I have generated some variables in the javascript which is on the jsp page. I want to assgin these variables to the jsp vaiables. Or how can I access javascript variables from jsp on the same jsp page.

  • Passing multiple single values in Customer Exit Variables

    Hi,
    I have one requirement to Pass multiple single values in Customer Exit Variable.
    If the user gives 2010 i need to get value previous fisacal year(2009),if its 2009, we need to get 2009.
    Just requirement is like how to pass multiple single values?
    Thanks.

    Hi..
    For this create a variable- Types of variable= Characteristics Value> Processing type as Customer Exit-->Reference Char as Fiscal year..
    Try this code..
        when 'xxxx'.
          DATA: lv_zp0003_month(2) TYPE n,
                  lv_zp0003_year(4) TYPE n.
          CLEAR: lv_zp0003_month, lv_zp0003_year.
          lv_zp0003_month = sy-datum+4(2).
          lv_zp0003_year = sy-datum(4).
    If the month is January the year is set to previous year
          IF lv_zp0003_month = '01'.
            lv_zp0003_year = lv_zp0003_year - 1.
           l_s_range-low = lv_zp0003_year.
    Else the year is set to actual
          ELSE.
            l_s_range-low = lv_zp0003_year.
          ENDIF.
          IF l_s_range-low = l_s_range-high.
            l_s_range-opt = 'EQ'.
          ELSEIF l_s_range-high IS INITIAL.
            l_s_range-opt = 'EQ'.
          ELSEIF l_s_range-low LT l_s_range-high.
            l_s_range-opt = 'BT'.
          ENDIF.
          l_s_range-sign = 'I'.
          APPEND l_s_range TO e_t_range.
    Hope this helps.
    Regards.
    AKG

  • 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

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

  • How to access a JAVA Script variable in JSP Code

    How to access a JAVA Script variable in JSP Code. I have been unable todo this.
    Plz Suggest a way.
    Thanks
    Soumya

    try to do this code
    String s=request.getParameter("javascriptvariablename");

  • Pass value of Java script variable to ABAP variable (in BSP)

    Hi,
    I have a Javascript variable declared in the SCRIPT tag of BSP layout page.
    I want to pass its value to ABAP variable, so that later I can do some computations using the ABAP variable.
    (ABAP variable is also declared in the same SCRIPT tag of BSP page)
    Would request to post a sample code, if possible.
    Would appreciate quick replies.
    Thanks & Regards,
    Nisha Vengal.

    just check this
    https://forums.sdn.sap.com/click.jspa?searchID=16240444&messageID=1191305

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

  • How to assign bean value to a local variable in JSP using struts.

    Hi everybody!
    I've a problem that puzzled me on how to assign a bean value to a local variable like String in JSP using struts.
    we can have someting like this to display the value
    <bean:write name="detailService" property="status" />or
    <bean:define id="theStatus" name="detailService" property="status"/>
         This is country: <%=theStatus%>but an error occured when I tried like this:
    String currentStatus = "<bean:define id="theStatus" name="detailService" property="status"/>";
    or
    String currentStatus = "<bean:write name="detailService" property="status" />";Is there a way to do this?.....
    Any help pretty much appreciated

    Java != JSP.
    The <bean:define> and <bean:write> tags are custom tags meant to appear in the HTML section of a JSP file, as opposed to the scriptlet section. They actually get turned into java code as part of the translation process.
    The <bean:write> tag naturally just writes out what you tell it to.
    The <bean:define> tag defines a local variable, and gives it a value.
    this should do it.
    <bean:define id="theStatus" name="detailService" property="status" type="java.lang.String"/>
    <%
      String currentStatus = theStatus;
    %>With the advent of JSTL, you shouldn't really need to use scriptlet code anymore. Personally I am for 0% scriptlet code in any jsp I write.

  • Setting the XML tag value in Java script

    Hi,
       I am trying to set a XML tag value in the initialize event of a text field.. The code works fine in FormCalc but I needed it to work in java script.
         FormCalc:
         $record.prospectApplication.typeName = "namedInsured";
         Java Script:
         xfa.record.prospectApplication.typeName = "namedInsured";
         The above JavaScript does not work. Can any one help on this?
    Thanks
    Srini

    Hi Srini,
    In JavaScript you don't get any default properties so you need to say;
    xfa.record.prospectApplication.typeName.value = "namedInsured";
    That is assign the value to the "value" property not the dataValue object.

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

  • Passing drop down value to java code

    Hi,
    I am using a htmlb dropdownlist element in a jsp file. And I have included the java code in the same jsp. I need to know how to pass the selected value from the drop down to the java code.
    Can anyone please help?
    Thanks & regards,
    Malita Fernandes

    Not a problem, please create a java bean class which is having setter and getter methods
    for example if you drop down name is Day and create bean class like
    public class week
               private Day;
               public void setDay(String day){
               this.Day=day;
               public String getDay() {
          return this.Day;
    JSP File
    <SELECT name=Day>
    <OPTION value="" selected>- Select -</OPTION>
    <OPTION value=Sunday>Sunday</OPTION>
    <OPTION value=Monday>Monday</OPTION>
    <OPTION value=Tuesday>Tuesday</OPTION>
    <OPTION value=Wednesday>Wednesday</OPTION>
    <OPTION value=Thursday>Thursday</OPTION>
    <OPTION value=Friday>Friday</OPTION>
    <OPTION value=Saturday>Saturday</OPTION>
    </SELECT>
    <% week w=new week();
    w.setDay(Day);  %>

Maybe you are looking for