How to access variables across JSP and JavaScript?

Hi,
I have some .js files and in those files, some of the methods need to access to the variables that I'd declare in the jsp files. How do I do it?
Anne

You can do it this way, but I'm not sure if this is what you had in mind.
Say you had a java variable called XString. And you wanted to display
the value of XString in a javascript Alert. Here's how:
<html>
<body>
<% String XString = "Hi There!"; %>
</body>
<script language="javascript">
alert("<%=XString%>");
</html>Hope This Help,
P.

Similar Messages

  • How to deliver variable between jsp and EL ?

    this is the code of my *.jsp
    <%
    int g_nAge=12;
    %>
    ${g_nAge}
    I suppose that "12" is showed in my web-page,but actually I see nothing.
    This is an example in my jsp book showing the delivering variable between JSP and EL !
    how can it do that ?

    EL cannot pick up scripting variables. It picks up attributes from scope only.
    Similarly it doesnt set any scripting variables too.
    <%
                  int g_nAge=12;
                  pageContext.setAttribute ("g_nAge", new Integer(g_nAge));
    %>
    ${g_nAge}cheers,
    ram.

  • How to share variable between jsp and JSF?

    hi:
    I have code :
    <h:dataTable binding="#{Tables.dataTable}" value="#{Tables.query}" var="currentRow">
    <h:column>
    <h:outputText value="#{currentRow['factorycode']}"/>
    </h:column>
    <%
    //here I want get upon variable currentRow and process some field.
    // but how java code I can get the currentRow,
    //currentRow is a ResultSet object
    %>
    </h:dataTable>
    thanks

    EL cannot pick up scripting variables. It picks up attributes from scope only.
    Similarly it doesnt set any scripting variables too.
    <%
                  int g_nAge=12;
                  pageContext.setAttribute ("g_nAge", new Integer(g_nAge));
    %>
    ${g_nAge}cheers,
    ram.

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

  • How to access variables declared in java class file from jsp

    i have a java package which reads values from property file. i have imported the package.classname in jsp file and also i have created an object for the class file like
    classname object=new classname();
    now iam able to access only the methods defined in the class but not the variables. i have defined connection properties in class file.
    in jsp i need to use
    statement=con.createstatement(); but it shows variable not declared.
    con is declared in java class file.
    how to access the variables?
    thanks

    here is the code
    * testbean.java
    * Created on October 31, 2006, 12:14 PM
    package property;
    import java.beans.*;
    import java.io.Serializable;
    public class testbean extends Object implements Serializable {
    public String sampleProperty="test2";
        public String getSampleProperty() {
            return sampleProperty;
    }jsp file
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.sql.*,java.util.*"%>
    <html>
    <head>
    <title>Schedule Details</title>
    </head>
    <jsp:useBean id="ConProp" class="property.testbean"/>
    <body>
    Messge is : <jsp:getProperty name="msg" property="sampleProperty"/>
    <%
      out.println(ConProp.sampleProperty);
    %>
    </body>
    </html>out.println(ConProp.sampleProperty) prints null value.
    is this the right procedure to access bean variables
    thanks

  • How can I pass a variable between JSP and Role Form

    I need to pass a variable from (a copy of) applicationmodify.jsp to the IDM Role Form so that the variable is available within the Role Form at display. We've tried getAttribute and setAttribute modifying both the Role Form and the applicationmodify JSP and can get the form to the role form but not accessible but have had no other success. Has anyone had any success in doing this? Any suggestions would be appreciated.

    if by _root level you mean you're loading something into
    _level0 you can't won't be able to use the localconnection. the
    sharedobject is your only option.

  • How to access variables passed in custom tag body

    I am developing custom tags in my application. I need to pass some variables from the .jsp file into tag file. I want these to be passed as body of the tag rather than as tag parameter. It seems the correct syntax for this is:
    <myTags:display> someVariable </myTags:display>
    Question 1: Can I not use this as: <myTags:display someVariable /> Since this tag will be used at many places in the jsp, I dont want to write myTags:display twice for every usage.
    Question 2:
    I want to call the tags from main.jsp like:
    <% String var1 = "Display Me Please"; %>
    <myTags:display var1 />I want the tag file to do some processing on the value stored in var1. I've written the following code in tag file, display.tag:
    <jsp:doBody var="theBody" />
    <% Object obj = (Object) request.getAttribute ("theBody"); %>This code snippet gives me access to obj which has the value "var1". Now how do I access the value that is contained in "var1".
    Edited by: coolkomal on Jun 3, 2009 7:45 AM

    coolkomal wrote:
    I am developing custom tags in my application. I need to pass some variables from the .jsp file into tag file. I want these to be passed as body of the tag rather than as tag parameter. It seems the correct syntax for this is:
    <myTags:display> someVariable </myTags:display>
    Question 1: Can I not use this as: <myTags:display someVariable /> Since this tag will be used at many places in the jsp, I dont want to write myTags:display twice for every usage.
    <myTags:display var="<%=someVariable>"/> is a valid syntax for performing respective action of that variable. You can also use EL to pass the variable ${someVariable} provided the custom tag provide support for EL.
    >
    Question 2:
    I want to call the tags from main.jsp like:
    <% String var1 = "Display Me Please"; %>
    <myTags:display var1 />
    Just ensure that you declare all the related variables in Main.jsp and statically include Main.jsp in your jsp such that you do the checking
    [http://java.sun.com/products/jsp/tags/11/syntaxref117.html]
    >
    I want the tag file to do some processing on the value stored in var1. I've written the following code in tag file, display.tag:
    <jsp:doBody var="theBody" />
    <% Object obj = (Object) request.getAttribute ("theBody"); %>This code snippet gives me access to obj which has the value "var1". Now how do I access the value that is contained in "var1".Can be done provided you code it the right way. Start learning basics of how to create custom taglibraries to gain more knowledge on how things can be managed.
    [http://java.sun.com/javaee/5/docs/tutorial/doc/bnalj.html]

  • Jsp and javascript problem

    I have a JSP page with a table of n rows. Each row has the option of having
              a dropdown list appear on that particular row. The user should have the
              ability to make a selection from the drop down list and have the page change
              to the correct page automatically or it can allow the user to change and
              have them click on a link that passes the value of the select box as a
              parameter to the proper page.
              The problem is that each row CAN NOT be in it's own form. The action for
              the current form is NOT the action I want the select box to use.
              I can't seem to figure out how to get the value of the select box in
              javascript passed as a parameter using a JSP variable.
              Example code:
              <form method="post" action="/index.jsp">
              <table>
              <tr>
              <td> Remove Row? </td>
              <td> View Options? </td>
              <td> Name </td>
              </tr>
              <tr>
              <td> <input type=checkbox name='<%=rowNumber %>' value='<%=
              someCheckboxValue %>'> </td>
              <td> <select name=selectOptions>
              <option value="option 1">option1</option>
              <option value="option 2">option2</option>
              <option value="option 3">option 3</option>
              </select>
                View Option  
              </td>
              <td> <%= rowName %> </td>
              </tr>
              <tr>
              <td colspan="3"> <input type=button name='UpdateExampleForm'
              value='Submit'> </td>
              </tr>
              </table>
              </form>
              

    actually i am taking menus from database in file ourmenu.jsp
    and i have another file called menu.js which displays the menus on browser
    menu.js is the file which i have downloaded from net
    and i want to use at it is but with a difference that it should display the menus which r coming from database
    in file ourmenu.jsp i have saved the menus in array so can anyone tell me how to refer them in my .js file.
    i have tried with foll. code::
    var aUsername =new array();
    <% i=0;
    while (padtemp[i] != null)
    %>
    aUsername[<%= ++i%>] = "<%= padtemp[i] %>";
    in .js file but i am getting no o/p on browser
    i have tried with runat=server while including the .js file in .jsp file but its not working too.
    can anyone help please
    thanks in advance

  • How to access variables outside user exit

    Hi,
    I'm working with a user exit and my problem is that in a particular moment I have to access variables located outside the scope of the user exit (they are in a standard program)
    How can I reach these variables?
    thanks in advance

    Hi,
    If they are global variables then you can access them using Global assign technique,
    For example,
    FIELD-SYMBOLS: <fs_value> TYPE ANY.
    ASSIGN ('(SAPMV45A)XVBAK') TO <fs_value>.
    It is basically,
    ASSIGN ('(<Std. Program Name>)<Variable name>') TO <field symbol>.
    NOTE: To make sure they are accessible in your user exit, just put a break-point in the user exit and once you are there in debugging, type in,
    (<Std. Program Name>)<Variable name> in the Field names section and if it does not show it in RED then it is accessible..
    Hope this helps.. 
    Sri
    Message was edited by: Srikanth Pinnamaneni

  • How to access variables??

    how to access public variables of any other class??
    suppose i have a file temp.java file ..& i know all the public variables. and
    i want to access the variable of those temp.class file which extends JApplet or Applet..
    and as u know it will declare public void init() .. & in this function only all declaration will be there.
    so now how to invoke this init() function from any mymethod()..to access public variables...

    its not working. for me..
    the variable which i m trying to access is non static.. its displays the error :
    Exception in thread "AWT-EventQueue-1" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
    and by one method i have connected database also.. and it has been called from init()..
    i have collected the data from the database..and i m storing the data in one ArrayList ..
    and i want to access that ArrayList..

  • How to Access Variables defined in the PopUpWindow

    Hi Friends
    I am building a flex site using flex builder 2.....
    Here I need your help.....
    My Problem is how to store a variable from a popup window
    I have this problem while in the login window comes as popup
    while clicking login button in the page a popup where user
    can enter username and password...
    after submitting if the login is successufl the popup
    vanish...
    After a successful login I need to store the logged user name
    in the main index page but I am not able to store
    At first I created a variable 'loggedUsername' in the popup
    panel and after success log i assigned the username to it ... after
    it i am not able to get the loggedUsername..
    doubting I defined the variable in the main index.mxml page
    but this variable is not accessible from the loginwidow.mxml page
    where the popup will function...
    Heip me
    how to store the name if the user login is success..
    thanks
    Chintu...

    Lets say you have a public property in your application like
    public var name:String = "John Smith";
    to access this using an inline item renderer:
    <mx:itemRenderer>
    <mx:Component>
    <mx:VBox>
    <mx:TextInput text={outerDocument.name} />
    </mx:VBox>
    </mx:Component>
    </mx:itemRenderer>
    To access variables of the applicaton you can use
    Application.application.name (for example) to reference "global"
    variables, so you might also use this technique. With an inline
    item renderer, the outerDocument property will refer to the
    component which contains the renderer.

  • How to access dataprovider through jsp syntax

    I am creating an image gallery but here's my issue...
    I have a database table that contains links to images on my file system. I created a dataprovider for this database table on my page so the dataprovider now returns all the image links.
    Now what I need to do is create a row of thumbnails so I add a scriptlet in my jsp code where I want the thumbnail to appear. This scriptlet loops through the dataprovider and for each row it will create a standard html image tag populating the src attribute with the link from the dataprovider.
    I figure creating dynamic html img tags is much easier than creating dynamic image components in the backing bean. Doing the former allows me to output the row of thumbnails exactly where I want them on the page (ie where i put my scriptlet code) and is easier to manage.
    The problem is i don't know how to access the dataprovider through jsp tags and syntax. I'm sure there must be a way, can anyone help?
    Thanks.

    I've done this sometimes using scriplets:
    <%
        request.setAttribute("SOME_CONST", Constants.SOME_CONST);
    %>
    <c:out value="${SOME_CONST}" />But I would also be interested if anyone knows a way without those ugly scriplet..
    O

  • How to do  validation in jsp using javascript

    how to do validation in jsp using javascript

    The same way you do with any HTML page.
    Catch the onclick/onsubmit event, do your validation in javascript and then allow/cancel the action as required.
    However this is javascript validation only - javascript can never call JSP code.

  • How to Customize the iemsa_customerdetailincl.jsp and IHSearch.class

    Hi
    I have a requirement, where i need to customize the way of look the email customer agent console is displaying the customer results in ebs suite. I need to get some more values from DB and need to modify the iemsa_customerdetailincl.jsp and also the default query is located in IHSearch.class file which is located in COMMON_TOP/oracle/apps/iem/solo/customer and these resultset is assigned to IHBean.class and we are accessing the IHBean and iterating thru the vector and using IHBean to display the results on the page.
    And also can you let me know where can i get the username from like ServletSessionManager or SessionManager classes. Please let me know how do i need to extend or customize the IHSearch and IHBean classes for the customization of jsps.
    And the EBS version is R12. Thanks.

    Hello All,
    Can someone in this Forum reply to my question. Thanks.
    N.

  • How to access to SSO username and password from JPDK

    Hello
    Does anybody know how to access, from Java PDK, to SSO username
    and password of user, currently connected to portal.
    Thank's,
    Tomaz Podbersic

    The portal user's password is one way hash algorithm (MD5) that
    cannot be reversed.
    What you'll have to do is setup a "External Application" and
    save an alternate username/password profile in that area. It
    requires the user to first enter that data (but only 1 time) the
    first time into that application.
    ===========================================
    <HELP NOTE>
    If anyone knows of an API to populate those tables when seeding
    or creating the user names to also seed or create the "external
    applications" user /pass this would be helpful.
    ============================================
    JSP java code:
    ====================
    PortletRenderRequest portletRequest = (PortletRenderRequest)
    request.getAttribute (HttpProvider.PORTLET_RENDER_REQUEST);
    ProviderUser myUser=(ProviderUser) portletRequest.getUser();
    =====================
    From this object instance you can get the user's name, and other
    Portal session info. NOT password.
    The External Application username & password is a bit more
    tricky to get.
    see:
    SQL Login Problems

Maybe you are looking for

  • Why after IOS6 Ipad calendar not syncing with Icloud?

    After I upgrade Iphone and Ipad to IOS6, my Ipad calendar doesn't sync with ICloud using exactly same Apple ID. Any sugestions?

  • Oracle 8.1.5 on Windows XP Pro

    Hi, I am trying to install Oracle 8.1.5 on windows XP pro, when installing i get the message saying "Invalid staging area". It will get a bit further if i run setup.exe in compatibility mode for Windows98, but seems to halt installation when trying t

  • Update to Mac OS X 10.4.6

    I've tried using the automatic updater and the standalone and everytime I try to update it will get as far as 16% writing files and then stops due to errors. How do I get around this to update my software? I'm new to Mac so not very knowledgeable. Pl

  • ABAP Function Module

    Hello Experts, I am working on requirement in which i m facing problem. I have an excel sheet with 5000 records. In which i shud retreive only last 2 charecters of a particular column. can anyoen help me what to write..? Thanks, varun. \[removed by m

  • Windows 7 for Macbook pro retina (no "superdrive)

    I hate this computer I got no dvd space for the Retina and I don't know how to install Windows 7 on this crap... I don't want to pop my 80 bucks for that useless item... what should I do?