Using vars declared in scriptlets in EL & vice versa

I'd like to reference the same variable in both a scriptlet and in some EL on a JSP page. Is there a different way to do this other than setting a pageContext attribute? For example, I'd like to do something like this:
Won't work:
<%
String theString;
// manipulate the string
%>
${theString}
Does work (but requires setting the pageContext attribute at the end of the scriptlet):
<%
String theString;
// manipulate the string
pageContext.setAttribute("stringFoo", theString);
%>
${stringFoo}Is there a better way to do this? I played around with jsp declarations and c:sets but to no avail. Thanks in advance.

Thanks, but it doesn't seem to be working for me, which is confusing. I am using jsp:useBean b/c my CTO doesn't want to use struts, so hopefully it's doable. Also, I tried using bean:define and kept getting the exception at the end of this post. Probably something I messed up when installing struts.
Here is some code that outputs the following:
1. outside scriptlet:
2. in scriptlet: world
3. outside scriptlet: foo
4. in scriptlet: worldLooks like ${test} is not corresponding to the bean called "test." Why would that be? And how then does the scriptlet know what the test variable is then if it is not associated with the useBean? I don't have any other type declaration on the page...
<jsp:useBean id="test" class="java.lang.String" scope="session"/>
<%
         test = "world";
%>
1. outside scriptlet: <c:out value="${test}"/>
<%
     out.println("2. in scriptlet: " + test);
%>
<c:set var="test" value="foo" />
3. outside scriptlet: <c:out value="${test}"/>
<%
     out.println("4. in scriptlet: " + test);
%>Now here's that exception I was getting when trying to do a simple
<bean:define id="test" name="test" type="java.lang.String"/>
java.lang.NoClassDefFoundError: org/apache/struts/util/MessageResources
     org.apache.struts.taglib.bean.DefineTag.<clinit>(DefineTag.java:47)
     sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
     java.lang.reflect.Constructor.newInstance(Unknown Source)
     java.lang.Class.newInstance0(Unknown Source)
     java.lang.Class.newInstance(Unknown Source)
     org.apache.jasper.runtime.TagHandlerPool.get(TagHandlerPool.java:116)
     org.apache.jsp.content.campaign.advancedCriteriaContent_jsp._jspService(advancedCriteriaContent_jsp.java:110)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
     org.apache.jsp.template.campaign_jsp._jspService(campaign_jsp.java:121)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
     org.apache.jsp.page.campaign.advancedCriteria_jsp._jspService(advancedCriteria_jsp.java:87)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Similar Messages

  • How to use javascript variable in BSP/ABAP and vice versa

    Hello Experts,
    In IC WEBCLIENT, there is a view.In the view.htm i want to fetch  the screen resolution and as per the resolution i want set the width of that view.
    1, I wrote the below  javascript to fetch the screen resolution.
       Can i use a notmal ABAP variable inside the javascript? and   If i use can i access that variable after the javascript.?
       Can i assign a javascript variable to a nrmal abap variable??
       The code sample  is like :
    Start of javascript
       if (screen,width == 1024 )
         lv_width = 500  "lv_width is an ABAP variable.
      else
        lv_width = 700
    **END OF JAVASCRIPT
       **Now i want to use lv_width  to assign to a table view attribute(Width)
    <crmc: tableview..
                    width = <%= lv_width >
    the code is not giving any error. But the problem is that lv_width is not giving the correct value, its getting initialized to initial value...
    Requesting the experts to please provide some suggestions/solution for the above issue.
    Thanks and Regards
    Sudhansu

    Hello Sudhansu,
    First of all there was a little mistake at my previous answer:
    you got lw_width = 700
    because at Server Side you have following code:
    lw_width = 500.
    lw_width = 700.
    but if you were writing your code like this:
    <%=lw_width %> = 700.
    then you will get the result that I was talking about : 0 = 700
    Sorry for the mistake
    Now for your question:
    if you want to get a value from the server and assign it to JScript variable you should write like this :
    var aaa;
    aaa = <%=lw_width %>;
    this code assign the server variable lw_width value into aaa  JScript varible.
    I'm not sure what exactly you want to do but look at this link:
    http://www.pageresource.com/jscript/jscreen.htm
    to get the idea how to get and use Screen Resolution variables at your JScript code.
    Good luck
    Eli Steklov
    Please Reward Points if it Helped

  • Invoking Forms from JSP and Vice versa

    Hi,
    I am in to a requirement like invoking a screen developed using Oracle Forms 6i from JSP and vice versa.
    1. Could you please anybody help to get the documents to be refered to get more idea on this?
    2. Is it possible only by Oracle ADF?
    Please help me on this.
    Thanks & Regards
    M Thiyagarajan

    Hi All,
    Thanks a lot for the clarifications.
    Actually, integration should happen between forms and JSP. Parameters need to be passed to and forth. I will go through the specified link.
    Also could you please clarify me where exactly, ADF comes into picture? or what are all the advantages when we go for ADF?
    Thanks & Regards
    M Thiyagarajan

  • Question about duplicate var declaration....

    the ff. code will compile and run... my question is there's a duplicate var declaration
    (s var as a String type)...
    Big Q: "Why the compiler didnt complain about it?"
    it should be "duplicate var declaration" sort of thing......
    public class Bits {
         public static void main(String args[]){
                  new Bits();
        public Bits(){
             f1();
        private String s; // class var declaration, var name is "s"
        private void f1(){
           // another var declaration name "s", why the compiler dont complain about this!?!
             String s=new String("Hello World!");
             f2();
        private void f2(){
        // does this var "s" refers to the class var?
             System.out.println ("s: "+s); // the output is null
    }Thanks!

    Big Q: "Why the compiler didnt complain about it?"
    it should be "duplicate var declaration" sort of
    thing......Bcos one is a local variable and the other is an instance variable. They arent duplicates.
    > private String s; // class var declaration, var name is "s"
    >
    private void f1(){
    // another var declaration name "s", why the compiler dont complain about >this!?!
         String s=new String("Hello World!"); As i said b4, this is a local variable. Within the scope of this method, this variable hides the instance var, 's' , to access which, u will have to use this.s
    >
    private void f2(){
    // does this var "s" refers to the class var?Yes.
    System.out.println ("s: "+s); // the output is null//that's bcos u havent initialized it anywhere. Local variable have to be compulsorily initialized. Instance variables are initialized to null (if they are Object references)
    ram.

  • Vars declaration

    Hello everybody,
    I've got a couple of questions about vars declaration, mainly inside methods. The thing is I read somewhere that since inside a method vars wont get a default value, you should declare them assigning its "natural" default, just as a good practice and to guarantee they don't get garbage at the value.
    public boolean declareVars(MyObject param) {
        boolean isEmpty = false;
        MyObject o = null;
        //do stuff
        isEmpty = o.equals(param);
        return isEmpty;
    }But in some other place said, you should not declare vars at the begining since this is not C++. Declaration should be done when you need the object for the first time. What would be a better advice?
    And to make the couple, here's the second. When you need a var thats gonna be instantiated inside a loop several times, is there any diference or advantage if I write the declare statement before the loop begins instead of insede the loop?
    //Outside the loop
    MyObject mo = null;
    for (MyObject item: myObjects) {
        mo = item;
    //  do stuff using mo
    //Inside the loop
    for (MyObject item: myObjects) {
       MyObject mo = item;
    //  do stuff using mo
    Thanks in advance for your advise.

    The general guideline is that a variable should be declared in as constrained a scope as possible -- within the block where it is used, if it does not need to be accessed from outside the block.
    is there any diference or advantage if I write the declare statement before the loop begins instead of insede the loop?From the performance standpoint, no difference. Semantically, if it makes sense that the variable be scoped within the loop, then that's where it should be declared.
    db

  • My nephew and I use the same iTunes account and when I add an app it is loaded on to his iPhone and vice versa... How do I make that stop?

    My nephew and I use the same iTunes account and when I add an app it is loaded on to his iPhone and vice versa... How do I make that stop? I have already unchecked the "Auto Update Apps" button. It happens with all purchases in the app store and on iTunes. HELP!

    I also think separate accounts is the way to go....if he is over 13yrs also remember if you do make an account for him and use your bank card all purchases will be charged to your card.

  • My wife and I got Iphone 4S same day 2 years ago. I used the same Apple ID for both. We do not use iCloud, but today after I updated my phone to IOS7 I keep getting her texts on my phone ans vice versa.

    My wife and I got Iphone 4S same day 2 years ago. I used the same Apple ID for both. We do not use iCloud, but today after I updated my phone to IOS7 I keep getting her texts on my phone ans vice versa. I turned off imessage in message settings. Seems to have stopped now? Never did this before IOS7. Will I have more troubble when her phone updates to IOS7? Is icloud going to be forced on me then?

    This is being caused by using the same Apple ID for iMessage on both phones.  To separate your messages, go to Settings>Messages>Send & Receive and do one of the following:
    Either uncheck the email address shown under "You can be reached by iMessage at" on both phones; or
    If you want to continue to receive iMessages at this email address, on one of the two phones, tap the Apple ID at the top, sign out, then sign back in using a different Apple ID.

  • My new iphone 5 email is synched with my home office computer Outlook email using a POP account, but deleting an email on my computer does not delete it on my phone and vice versa.  Is there any way to get a true synch?.

    My new iPhone 5 email is synched with my home office computer Outlook email using a POP account, but deleting an email on my computer does not delete the email on my phone and vice versa.  Is there any way to get a true synch?.

    POP does not support synchronization between the server and clients. You will need to use IMAP or Exchange Active Sync if your email provider supports it.

  • What are the uses of declaring a class "final"?

    Can any one please tell me the uses of declaring a class "final"?
    I know that final classes cannot be extended. Other than this,
    Is there any thing that will improve the compiler time for the final classes?

    compiler performance is utterly unimportant anyway...
    If the compiler takes too long, just get a faster build system :)

  • Data transfer between SAP & Java and Vice versa using IDOC Process

    Dear Experts,
            We are working on one of the good requirement related to data transfer between SAP and Java software. Client requirement is, they want to transfer the data in both the ways (from SAP --> Java and Vice versa also).
    In detail is, after sales order creation using one custom program loading plan details will be calculated. Once loading dates are confirmed then, user will release the sales document to transfer the data from SAP to Java using "Outbound IDOC processing". Similarly in that JAVA software some shipment details will be performed, once completed from JAVA software again details needs to be pumped back to SAP as "Inbound IDOC Processing".
    For this fields are already identified from external software SAP and we are looking for the same to perform the steps in SAP.
    At this stage, I need your expert opinion  / feedback how to go  about at this stage.
    Meaning,  
                     1. What are the customizing steps needs to be done in SAP..?
                     2. How to trigger the :Outbound IDOC process" once the documents are "Released" from custom transaction
                     3. How to create the link between SAP and JAVA to transfer the data between these 2 software
                     4. How to trigger the "Inbound IDOC Process" from JAVA software to SAP and how to store the data in SAP
    Experts, please give your feedback in terms of reply or by sending the step by step process to fulfill this client requirement.
    Thanks for your cooperation.
    Regards,
    Ramesh

    Maybe too many open questions in the same document.
    Maybe you should repost a more specific question in a technical forum.
    This looks like a small project where you already know what you want, maybe you should contract a technical specialist so he proceeds to the implementation!

  • Use of declaring an interface inside an interface

    Hi
    Whats the use of declaring an interface inside an interface? I can make some guesses by my own but want to come up with some
    solid reasoning.
    So any view points are welcome
    public interface ParentInterface{
    interface ChildInterface{
    public void inside();
    thanks
    Harshit

    CeciNEstPasUnProgrammeur wrote:
    kajbj wrote:
    One reason could be that the outer interface has a method that takes a callback implementation as argument. The nested interface is in that case the contract that the callback method must implement. I don't see a reason to declare that callback interface at top level.That's what I meant. Although I see very few reasons (namely one - limited usage, which might change) not to declare it at top level, because you can't make it less visible, like one might do with an inner class implementing a public interface.
    There is no technical reason for it and no technical reason against it, and whether or not seems just to be a matter of personal taste.I agree. But it can also make it easier to navigate the code. Now people can see that the NotificationListener interface only is important if you are going to use or implement a processor (but that could kind of be done with packages as well)
    I just don't like the looks of "class Myclass implements SomeInterface.InnerInterface".Neither do I, and I would probably create an anonymous implementation that just delegates.

  • I am interested on buying the Photoshop and Lightroom package (9.99 per month) My question is If I download it on my PC can I also use it on my iMac or vice versa?

    I am interested on buying the Photoshop and Lightroom package (9.99 per month) My question is If I download it on my PC can I also use it on my iMac or vice versa?

    If you want to have the photos stored on an external HD, you probably should move them there in your operating system before you import into Lightroom.
    But, if you don't yet own an external HD, you can import from the internal hard drive and later move the photos to wherever you want them to be, as long as you do it properly.

  • I have 2 macbooks using airport.  I can send emails from 1 mac to the other but not vice versa.  Any ideas why?

    When we set up the airport we used to be able to send emails from my macbook to my husband's macbook and vice versa but can't now.  We have different email addresses and it was convenient to be able to forward emails etc. Can anyone tell me if it is the airport or the way we have our macs set up.  Thank you.

    I really don't think it's the router. Most likely, it will have to do with the email client that you are using on each of your Macs. Unless you are running an eMail server on your local network, both of your eMail clients are using mail servers on the Internet.
    If you are both using OS X Mail, you may want to post in that forum area as well to see if the Mail experts over there can help.

  • My iPhone4 and laptop have stopped communicating/syncing in terms of emails. IE: If I delete an email on my phone, it used to automatically delete on my computer, and vice versa. Now, nothing. Help?

    My iPhone4 and laptop have stopped communicating/syncing in terms of emails. IE: If I delete an email on my phone, it used to automatically delete on my computer, and vice versa. Now, nothing. Help?

    I have a .mac account and a gmail account and have not moved to iCloud.

  • Display color profile bug when using the fast account switch from a guest account to an admin account (and vice versa)

    Hey,
    I'm sometimes using a guest account on my MBP (unibody late 2008 2,4 GHz Core2Duo, 4GB DDR3 running OSX 10.9.4 on an OCZ 128GB SSD) for a more distraction-free working space and I noticed right away a disturbing bug:
    Using the fast account switch (upper right hand corner of the screen) in Mavericks from an admin account to log into a guest account (or vice versa) produces, after the fancy rotating cube animation, some strange distortion of the desktop background happens (lasting approx. 2 sec.). After that the color profile of the display is changed into an usable but ugly one, which is disturbing while working with pictures. When checking the color profile in the pref pane, the standard "display" profile is said to be active (it's the one I use) but still the colors aren't the same. Selecting another profile and re-selcting the desired one doesn't fix the problem. Switching back to the other account with the fast switching leaves the colors altered. Logging out and deleting the guest account seems to the problem for the remaining admin account. Rebooting  and logging in to either of the accounts (admin or guest) from the standard account selecting page at booting shows the normal color profile.
    Is it a general bug or is their anything a can do to prevent this problem (other than never using the fast switching)?
    Thanks for your advice.
    Mael

    I cannot agree more with your comments! What a way to frustrate your customers!
    I have been having an issue with iCloud on Mac where it kept asking me for my password and sometimes would, sometimes would not continue to access my iCloud mail. Today it just refused to connect to iCloud mail.
    I looked in the Mail, Contacts and Calendars in my MacBook Pro settings and discovered that 2 iCloud accounts were present. One with my original Apple ID (a gmail address) and a second with my new iCloud email ( an @me.com address). Having deleted the second account, using the new @me.com address everything is working fine.
    So from my viewpoint when I moved over to iCloud I was asked to sign in with my Apple ID (the gmail address) then to create an @me.com address. However, as far as I can see all sign ins to the new @me.com account on Macbook, iPhone and iPad need to be done through the old Apple ID (the gmail address). Is that confusing and just plain crazy???
    Further, after creating the new @me.com address I soon found out that this is apparently now forever bound to my old Apple ID and cannot be changed. I mean why can't I delete the iCloud account and start anew with a different @me.com address??? Also, as everybody using iCloud must create an @me.com address why on earth can I not get rid of my old gmail address and have my entire Apple ID accessed through the new @me.com address? Creating a whole new Apple ID will not solve this as we are unable to transfer purchases between accounts.
    Apple products are great IMHO, but they do seem to not think things through in a very big way sometimes......

Maybe you are looking for

  • Simple costing

    There is scenario like Job work sales order against Sub contract purchase order, which same received from one of the internal customer. Now business would like do simple costing based on Job work sales order and subsequent settlement also. Let us kno

  • Change slide size without resizing objects?

    Is it possible to change the slide size without causing Keynote '09 to resize all the objects on each slide?

  • I can't choose multi dimension member for report and summary by quarter

    Dear Masters in SAP BPC, I am a newbie on BPC Netweaver, I am doing  practices follow by SAP BussinessObjects Planning and consolidation (Sridhar Srinivasan and Kumar Srivinasan) . At chapter 5 , I made a report as below: create a report : click BUIL

  • Monitor Changes in  PRD System

    Hi, Is there any transaction Code to monitor the changes (a log file kind of thing) that were made to the objects in the production system on day to day basis ? If there is no such transaction code is there any other way to trace the changes any work

  • At PC boot NiPal Service Mgr fails and exits

    When the PC boots the operating system complains that NiPal Service Mgr needs to shut down. This occured after I had run a LwCVI program that locked up the computer so I cycled the power to get it back. I corrected this once by reinstalling LwCVI. Is