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.

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

  • How can I access global variables in a loaded Applescript?

    How can I access global variables in a loaded script, in Xcode, ApplescriptObjC? Basically, I have a global variable defined in my parent script using "property", and I need to modify objects connected to those variables inside of a loaded script.
    Example:
    Parent script:
    script AppDelegate
    property myTextField : missing value
    //linked to a text field object
    tell myScript to myAwesomeHandler_()
    end script
    Loaded script:
    on myAwesomeHandler_()
    myTextField's setStringValue_("The new Xcode is so glitchy ugh")
    //changes value of linked text field of parent script
    end myAwesomeHandler_
    The problem is, the variable is undefined in the Loaded script, and I need it to have the same value as the parent script, and I don't want to pass the variable through the Handler. Any ideas?

    I think want you are looking to do will need to be done in two steps. Because myTextField needs to be a property for the ObjectiveC part of the code you cannot turn it into a global.
    However if you make a temporary variable global assign the string to it in the handler then set myTextField off of it.
    global myTextFieldGlobal
    script AppDelegate 
    property myTextField : missing value 
    //linked to a text field object 
    tell myScript to myAwesomeHandler_() 
    myTextField's setStringValue_(myTextFieldGlobal)
    end script 
    on myAwesomeHandler_() 
    set myTextFieldGlobal to "The new Xcode is so glitchy ugh"
    //changes value of linked text field of parent script 
    end myAwesomeHandler_ 
    I know you stated you did not want the handler to return a value but I have to ask why? Global's, imo, are not a good idea and really should be used as a last resort.
    One other possibility is to pass a reference to the property to the handler. Not sure if that works in AS of if that would satisfy our requirement of not passing the variable through the handler
    <edit>
    Another though have you tried to define the property outside the script?  That is
    property myTextField : missing value
    script AppDelegate
    Not sure if that will work.
    You might also want to have a look at Scope of Properties and Variables Declared in a Script Object

  • Accessing JSP Variables in Custom Tag Handler.

    Hi,
    I am creating a custom tag which builds a list view. I have certain String array in my JSP and I need to pass the same into my Tag Handler class. I tried following ways :
    1. In doStartTag() implementation I used
       public int doStartTag() {
             String[] myArray = (String[])pageContext.getAttribute("mystringarray", PageContext.PAGE_SCOPE;
       }This is not recognizing the String array variable defined in my JSP.
    2. I used separate attribute which is passed from the JSP to the custom tag as parameter having "rtexprvalue" as true. But I cann't pass a Sting array into my tag handler class. I can pass only String.
    How can I access variables which are defined in the JSP using declaration block. i.e.
    <%!
    String[] myArray = new String[100];
    %>
    Thanks for the time.

    You should be able to pass any type you like as an attribute to the tag.
    You just have to define its type as String[] in your tld:
    <attribute>
    <name>stringArray</name>
    <required>false</required>
    <rtexprvalue>true</rtexprvalue>
    <type>java.lang.String[]</type>
    </attribute>
    Alternatively, If you declare your array like:
    <%!
    String[] myArray = new String[100];
    %>You can do this:
    pageContext.setAttribute("mystringarray", myArray);
    which will put it into the page context for you to pick up in your custom tag.
    Hope this helps,
    evnafets

  • Can I access Infoset variable from Crystal Reports

    Hi,
    In order to connect Crystal Reports 2008 to the SAP environment I have the Integration kit.
    I have learnt that Crystal also offers InfoSet driver to connect to SAP.
    If I need to access SAP BI- Infoset variables inside Crystal Reports is it possible to do that. If no, then do I need to have the filter using the variable value instead of the fixed filter value?
    Please suggest.
    Thanks,
    Amogh.

    Hi Amogh,
    the InfoSet connectivity that Crystal Reports offers as a direct Infoset connectivity is towards the classic InfoSets from ERP.
    see here:
    /people/ingo.hilgefort/blog/2008/02/07/businessobjects-and-sap-part-i
    /people/ingo.hilgefort/blog/2008/03/23/businessobjects-and-sap-part-4
    In case you want to connect to an InfoSet in a BW system you would put a BW query on top of the InfoSet and then use the BW Query in Crystal Reports.
    see here:
    /people/ingo.hilgefort/blog/2008/02/19/businessobjects-and-sap-part-2
    Ingo

  • Virtual Char - How Can I access report variable in COMMPUT method

    I want to acess the Variables of a query in the COMPUTE method of a BADI for implementing a viratual characteristics.
    Can some one let me know how this can be done.
    Thanks
    Amit

    Hi,
    Following threads may be useful for you.
    How to implement Virtual Characteristics or Virtual key figures
    How to implement Virtual Characteristics or Virtual key figures
    Virtual Characteristics...
    /community [original link is broken]forumID=134&threadID=16617&messageID=131078
    Regards,
    Vishnu

  • Can't access JSP after deployment

    I deployed my BC4J app to OC4J, and was able to access my main.html. But I got the following error when trying to access my JSP pages from main page:
    500 Internal Server Error
    OracleJSP:
    JSP Error:
    Request URI:/PracticeWorkspace-DataJSP-context-root/GiftCertificatesView_Browse.jsp
    Exception:
    java.lang.NoClassDefFoundError: oracle/jbo/common/ampool/ApplicationPoolException
         at java.lang.Class.getMethods0(Native Method)
         at java.lang.Class.getMethods(Unknown Source)
         at oracle.jsp.parse.JspBeanInfo.determineSetPropertyOverloading(JspBeanInfo.java:371)
         at oracle.jsp.parse.JspBeanInfo.getSetProperty(JspBeanInfo.java:681)
         at oracle.jsp.parse.JspBeanDictionary.getSetPropertyInfo(JspBeanDictionary.java:191)
         at oracle.jsp.parse.JspRTTag.getSetProperties(JspRTTag.java:739)
         at oracle.jsp.parse.JspRTTag.validateTagParse(JspRTTag.java:404)
         at oracle.jsp.parse.JspParseTag.parse(JspParseTag.java:887)
         at oracle.jsp.parse.OpenJspTagHandler.parse(OpenJspTagHandler.java:585)
         at oracle.jsp.parse.JspParseTag.parseNextTag(JspParseTag.java:661)
         at oracle.jsp.parse.JspParseTagFile.parse(JspParseTagFile.java:172)
         at oracle.jsp.parse.OracleJsp2Java.transform(OracleJsp2Java.java:118)
         at oracle.jsp.runtimev2.JspPageCompiler.attemptCompilePage(JspPageCompiler.java:331)
         at oracle.jsp.runtimev2.JspPageCompiler.compilePage(JspPageCompiler.java:204)
         at oracle.jsp.runtimev2.JspPageInfo.compileAndLoad(JspPageInfo.java:361)
         at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:483)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:257)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:423)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:346)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:336)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:691)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:276)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:737)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:247)
         at com.evermind.util.ThreadPoolThread.run(ThreadPoolThread.java:64)
    Deployment log:
    Beginning to deploy to Oracle9i Application Server...
    Wrote WAR file to D:\JDev\MyWork\PracticeWorkspace\DataJSP\src\DataJSP_jpr_War.war
    Wrote web EAR file to D:\JDev\MyWork\PracticeWorkspace\DataJSP\src\DataJSP_jpr_War.ear
    Invoking Oracle9iAS admin tool...
    D:\JDev\jdk1.3\jre\bin\javaw.exe -jar D:\OC4J\j2ee\home\admin.jar ormi://1057198A admin **** -deploy -file D:\JDev\MyWork\PracticeWorkspace\DataJSP\src\DataJSP_jpr_War.ear -deploymentName PracticeWorkspace-DataJSP-app
    Auto-unpacking D:\OC4J\j2ee\home\applications\DataJSP_jpr_War.ear... done.
    Auto-unpacking D:\OC4J\j2ee\home\applications\DataJSP_jpr_War\DataJSP_jpr_War.war... done.
    Copying default deployment descriptor from archive at D:\OC4J\j2ee\home\applications\DataJSP_jpr_War/META-INF/orion-application.xml to deployment directory D:\OC4J\j2ee\home\application-deployments\PracticeWorkspace-DataJSP-app...
    Auto-deploying PracticeWorkspace-DataJSP-app (New server version detected)...
    Exit status of Oracle9iAS admin tool (-deploy): 0
    D:\JDev\jdk1.3\jre\bin\javaw.exe -jar D:\OC4J\j2ee\home\admin.jar ormi://1057198A admin **** -bindWebApp PracticeWorkspace-DataJSP-app DataJSP_jpr_War http-web-site /PracticeWorkspace-DataJSP-context-root
    Exit status of Oracle9iAS admin tool (-bindWebApp): 0
    ---- Deployment finished. ---- Jun 26, 2002 12:40:59 PM
    URL I used to access my main page:
    http://137.20.189.130:8888/PracticeWorkspace-DataJSP-context-root/main.html
    Please help.

    Juan,
    Please ignore my previous email.
    I got it work after I tried "Loading BC4J Runtime Libraries to OC4J". But...
    I have problem starting one browse JSP page. I created two browse JSP pages, and they are almost identical expect for referencing to different Oracle tables. Surprisingly one works fine while the one doesn't work and kills OC4J when I click to open. The error is the normal IE "The page cannot be displayed". It shows the page title for a second, and then gives the error and stops OC4J.
    Do you have any ideas? Thanks.
    Dan

  • Set Core Prefix , can value be a variable ?

    <c:set var="foo" scope="session" value="bar"/>
    <%
    String varSet = (String)session.getAttribute("foo");
    %>
    For the above variable output is bar...simple
    now instead of value = "bar"
    can we have
    String test = "bar";
    <c:set var="foo" scope="session" value="${test}"/>
    Is this possible ?

    Sorry, JSTL can't access scriptlet variables directly like that.
    You would have to use a regular jsp <%= expr %>
    So if you have a JSP2.0 container, this would work:
    <c:set var="foo" scope="session" value="<%= test %>"/>or this would work in any container (but only with string values):
    <c:set var="foo> scope="session><%= test %></c:out>Cheers,
    evnafets

  • Accessing session variables

    Hi ,
    I have session variable defined using portals (forms or plsql portlets).
    Can i access these variables using jsp portlets ??
    This is an urgent requirement ..
    Regards,
    Vijaya

    "145822",
    If your application with application id 100, for example, uses a common authentication scheme with application 200 (using the same cookie name in the case of an HTML DB style authentication scheme), then the two applications can run in the same session. A potential benefit of this, even if the two apps are not intricately related, is that the user has only to authenticate once per new session and will have access to both apps. If you set it up this way, then app 100 can access app 200's items in the same session using this function from within app 100:  htmldb.application.fetch_app_item(p_item=>'ITEM_NAME',p_app=>200);Scott

  • Accessing container variable of BPM in Message Mapping function

    Hi,
    I have a scenario in BPM where i have a container variable that is used as a loop counter.I want to access that counter defined , every time when i go around the loop and perform certain actions based on that counter. so how can i access that variable in my message Mapping function.

    Hi Sudharshan,
    check these links, hope they give you the required information (i think there is some problem with SDN site, check these links after a while)
    Re: How to use Container Variable across Maps
    Container object in Message Mapping
    Copy value of container (abstract interface) to an other container
    Regards
    Vishnu

  • Accessing  report variable

    Hi, i am creating one function module, i need to return one internal table IT_OUTPUT, that is ok,  the total logic for filling of IT_OUTPUT is written in one report, this ALV report which is used internal table IT_OUTPUT for grid display, Now my issuse is using this report how to get the data of output internal table  ie IT_OUTPUT from that report. There is no export of output table in the report to memory and i don't want to change this report at all. How can i access the variable IT_OUTPUT into my function module.

    Cut & paste the report code into function module, and kept only the code that deriving the IT_OUTPUT table .
    or
    change the report code and export the IT_OUTPUT table into memory and import in the function module
    or
    use Implicit Enhancment spot in the report and export IT_OUTPUT to memory

  • Accessing public variables from other classes

    Probably a simple questions, but how can I access a variable from another class. My exact situation is as follows.
    A class called WorldCalender has a variable which is defined: public int hour; (the value is given to it elsewhere).
    I want to access this variable and increase it by one in a subroutine in the class Hour. In this class I have put: WorldCalender.hour++; but it doesn't seem to work. How should I do it?

    don't expose the hour variable at all.
    have a method eg addToHourBy( int hrs )
    Probably a simple questions, but how can I access a
    variable from another class. My exact situation is as
    follows.
    A class called WorldCalender has a variable which is
    defined: public int hour; (the value is given to it
    elsewhere).
    I want to access this variable and increase it by one
    in a subroutine in the class Hour. In this class I
    have put: WorldCalender.hour++; but it doesn't seem to
    work. How should I do it?

  • Accessing session variables with php

    I am trying to access the  session variable  $_SESSION['MM_Username']  in one of my php pages, but it is somehow showing empty (i.e it does not contain the username that was entered during login).
    I checked and confirmed that my login.php function is properly setting the MM_Username session variable by echoing it  from the login function.
    So why can't I read it from another php file in the same session?  Do I need to do something else before the session variables can
    be properly read from any php file in the same session?  Any help would be appreciated.

    Here is a test code I am using to access the session variable $_SESSION['MM_username']  from  the php page  test.php. But it is not working.
    I get an empty string all the time for $username. Can any one see something wrong with this code?
    <?php require_once('Connections/MyTestingConn.php'); ?>
    <?php session_start(); ?>
    <?php
    $username = "-1";
    if (isset($_SESSION['MM_username'])) {
      $username = $_SESSION['MM_username'];
      echo $username;
    else
       echo "Eror: can not access session variable";
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    </head>
    <body>
    </body>
    </html>

  • Forms 9i accessing package variables

    I created a package in my sql session which contains only variables. When I connect to the database through Oracle Forms and try to access these variables in a trigger I receive the error "Cannot directly access remote package variables or cursor" How can I access these variables from within a forms module?

    You cannot access package variable or constants directly from a remote PL/SQL client. Only PL/SQL running on the server can access these. You need to implement get and set methods in the package.

Maybe you are looking for

  • Firefox keeps coming up with a site as my homepage no matter what I do

    I have been using Firefox for years, but I am at a point where I am going to go to IE. Whenever I bring up Firefox, it is a crap shoot as to whether I am going to get the Firefox start page or a site that I installed on the web. I have reset the home

  • The "Normal Brush Tip" cursor is appearing as the "Full Brush Tip" cursor in Photoshop CC.

    In spite of resetting all presets, restarting, etc., the Normal Brush Tip cursor is appearing as the Full Brush Tip cursor in Photoshop CC. The Full Brush Tip cursor is working as it should. Photoshop CC 14.1.2 x64 OS X 10.9

  • 32-bit Versus 64-bit

    Though this question could be abstracted out to apply to more than just Visual Studio, I'm really only concerned with Visual Studio and hope I can get some insight on 32-bit applications versus 64-bit. I have a 64-bit machine running Windows 8.1, wit

  • Project Detail Page issue

    Hi guys, My question is on Project Detail Pages. I  I created a Page Detail Page and gave it a title. However, after capturing the details in the PDP form and then closing the form so my details could be saved and checked-in, I get the following erro

  • Safari and Microsoft Messenger

    Hey All, So I downloaded the beta of Safari the other day on my MBP. Ever since then, my Microsoft MEssenger crashes when I close conversations. Anyone else having the same problems? Is there another program out there that I can use to IM with people