NEED HELP WITH USING STATIC METHOD - PLEASE RESPOND ASAP!

I am trying to set a value on a class using a static method. I have defined a servlet attribute (let's call it myAttribute) on my webserver. I have a serlvet (let's call it myServlet) that has an init() method. I have modified this init() method to retrieve the attribute value (myAttribute). I need to make this attribute value accessible in another class (let's call it myOtherClass), so my question revolves around not knowing how to set this attribute value on my other class using a static method (let's call it setMyStuff()). I want to be able to make a call to the static method setMyStuff() with the value of my servlet attribute. I dont know enough about static member variables and methods. I need to know what to do in my init() method. I need to know what else I need to do in myServlet and also what all I need in the other class as well. I feel like a lot of my problems revolve around not knowing the proper syntax as well.
Please reply soon!!! Thanks in advance.

class a
private static String aa = "";
public static setVar (String var)
aa = var;
class b
public void init()
a.aa = "try";
public static void main(String b[])
b myB = new b ();
b.init();
hope this help;
bye _drag                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Need help with project (calling methods) please!!

    Hi there i have a project for uni requiring me to create a java program that creates a random No. and lets the user have three guesses to find the No. When the users guesses correct he gets a message telling him hes won and if he doesnt get it correct he gets a message telling him the correct No then terminates.
    The code has to call an outside method called[b] Public Static Boolean CheckGuess
    I have tried to create this and got it to compile with no errors (eventually) but i keep getting a message saying i have whenever i type any number in. I think the problem is the way i am calling the method i havnt got much experience this is all pretty new to me any help would be really appreciated. Thanks.
    import javax.swing.*;
    import java.util.*;
    public class Coursework1{
         public static void main(String args[]){
              int randomnumber,usersguessint,checkguess,guessvalid,attempts;
              String usersguess,output;
              boolean match;
              //create random number generator
              Random numGenerator = new Random();
              //generate a random number between 1 & 10 inclusive
              randomnumber = Math.abs(numGenerator.nextInt(9))+1;
              //initialize variable attempts
              for ( attempts = 0; attempts < 3; attempts++ ) {
                   //ask user for his first guess
                   usersguess=JOptionPane.showInputDialog("Please enter your guess between 1 & 10");
                   //convert users guess to integer
                   usersguessint = Integer.parseInt(usersguess);
                        //validate input
                        while (usersguessint<1||usersguessint>10){
                        usersguess=JOptionPane.showInputDialog("You entered an incorrect number \nPlease enter a numberbetween 1 & 10");
                         //convert users guess to integer
                        usersguessint = Integer.parseInt(usersguess);
                        } //end while loop
                             //call boolean method
                             if (match=true){
                             //display text area in JoptionPane
                             output="You won";
                             JOptionPane.showMessageDialog(null,output,"You Won",JOptionPane.INFORMATION_MESSAGE);
                             break;}
                             else{
                             output="Try again";     
                             JOptionPane.showInputDialog("Try again");
                                  }     //end if
                   } //end for
              }//end main
                             //user defined method
                             public static boolean checkGuess(int usersguessint,int randomnumber){
                             boolean match = false;
                             if (usersguessint == randomnumber){
                             match = true;
                             return match;
                             }//end method
         }//endclass

    Thank you very much that worked a treat the program is working better now. I have just realised that my for loopcontaining my counter may be in the wrong place as the program is running though both messages 3 times e.g
    "Please enter your guess between 1 & 10"
    "Try again"
    "Please enter your guess between 1 & 10"
    "Try again"
    "Please enter your guess between 1 & 10"
    "Try again"
    "Please enter your guess between 1 & 10"
    "Try again"
    I want my program to run like
    "Please enter your guess between 1 & 10"
    "Try again"
    "Try again"
    "Try again"
    Do u think if i placed my for stament (counter) in between the two messages it would eliminate this problem.

  • Need help with freezing...please respond!

    I just got my reconditioned ipod mini yesterday. The problem is that at the main menu the scrolling mechanism works (thumb rotation), but the select button does not (I can't get into any submenus). I called Apple support, and they said to reset. I did this; the mini worked OK once, but then started to freeze up again, and now, no matter how many times I reset, it doesn't help...I'm stuck at the main screen, and the select button won't do anything. The apple support guy says he has to reset his mini 2-3x a week, but I've been able to make my ipod work only once or twice, and I've had it a day. PLEASE HELP.

    I keep trying that too...doesn't seem to help. Have tried plugging it into the AC adapter and resetting; doensn't help. Updated my ipod/itunes software; doesn't help. I don't want to try restarting the ipod; I just spent 6 hours putting music on itunes today, and don't know how to create a backup...and I read the restart instructions and don't know how to do all of the steps. Its amazing to me that this unit works so poorly literally the first day out of the box. How disappointing.

  • Need Help with a getText method

    Gday all,
    I need help with a getText method, i need to extract text from a JTextField. Although this text then needs to converted to a double so that i can multiply a number that i have already specified. As you may of guessed that the text i need to extract already will be in a double format.e.g 0.1 or 0.0000004 etc
    Thanks for your help
    ps heres what i have already done its not very good though
    ToBeConverted.getText();
    ( need help here)
    double amount = (and here)
    total = (amount*.621371192);
    Converted.setText("= " + total);

    Double.parseDouble( textField.getText() );

  • Need help with threads?.. please check my approach!!

    Hello frnds,
    I am trying to write a program.. who monitors my external tool.. please check my way of doing it.. as whenever i write programs having thread.. i end up goosy.. :(
    first let me tell.. what I want from program.. I have to start an external tool.. on separate thread.. (as it takes some time).. then it takes some arguments(3 arguments).. from file.. so i read the file.. and have to run tool.. continously.. until there are arguments left.. in file.. or.. user has stopped it by pressing STOP button..
    I have to put a marker in file too.. so that.. if program started again.. file is read from marker postion.. !!
    Hope I make clear.. what am trying to do!!
    My approach is like..
    1. Have two buttons.. START and STOP on Frame..
    START--> pressed
    2. check marker("$" sign.. placed in beginning of file during start).. on file..
         read File from marker.. got 3 arg.. pass it to tool.. and run it.. (on separate thread).. put marker.. (for next reading)
         Step 2.. continously..
    3. STOP--> pressed
         until last thread.. stops.. keep running the tool.. and when last thread stops.. stop reading any more arguments..
    Question is:
    1. Should i read file again and again.. ?.. or read it once after "$" sign.. store data in array.. and once stopped pressed.. read file again.. and put marker ("$" sign) at last read line..
    2. how should i know when my thread has stopped.. so I start tool again??.. am totally confused.. !!
    please modify my approach.. if u find anything odd..
    Thanks a lot in advance
    gervini

    Hello,
    I have no experience with threads or with having more than run "program" in a single java file. All my java files have the same structure. This master.java looks something like this:
    ---master.java---------------------------------------------------
    import java.sql.*;
    import...
    public class Master {
    public static void main(String args []) throws SQLException, IOException {
    //create connection pool here
    while (true) { // start loop here (each loop takes about five minutes)
    // set values of variables
    // select a slave process to run (from a list of slave programs)
    execute selected slave program
    // check for loop exit value
    } // end while loop
    System.out.println("Program Complete");
    } catch (Exception e) {
    System.out.println("Error: " + e);
    } finally {
    if (rSet1 != null)
    try { rSet1.close(); } catch( SQLException ignore ) { /* ignored */ }
    connection.close();
    -------end master.java--------------------------------------------------------
    This master.java program will run continuously for days or weeks, each time through the loop starting another slave process which runs for five minutes to up to an hour, which means there may be ten to twenty of these slave processes running simultaneously.
    I believe threads is the best way to do this, but I don't know where to locate these slave programs: either inside the master.java program or separate slave.java files? I will need help with either method.
    Your help is greatly appreciated. Thank you.
    Logan

  • Need help with flash player installation please !!!!

    Hello,
    I need help with my flash player installation because every time I access a movie this is the message I receive. 
    This content on Xfinity TV is not available for viewing with Chrome's "Incognito" mode. To play this video using Chrome, please view this page without "Incognito" mode.
    Still having problems? Try resetting your Flash player license.

    Incognito mode is a Google Chrome setting when you open a new window (Cmd+Shift+N on a Mac Ctrl+Shift+N on Windows) It opens a "private" window with no cookies and no tracking. The problem with it is that when you disable cookies, your license files are not sent to the site (whetehr it's YouTube or xFinity or any other that uses license files for paid content)  and it treats you as if you're a first time visitor. Paid videos won't play wihtout the cookies sending the license file info.
    This isn't a Flash Player setting. It's in Chrome. I did some research and according to Google, "Incignito" mode is off by default, and can ONLY be activate by the keyboard shortcut. There IS a way to disable it from the registry http://dev.chromium.org/administrators/policy-list-3#IncognitoModeAvailability

  • Need help with using Solaris FLAR across disparate platforms

    All,
    I need help with what needs to be done to use solaris Flash for disaster recovery between the disparate Server platforms listed below.
    I am concerned about the platform specific files that would be missing?
    Note: All our servers are installed with the SUNWCprog cluster through Custom jumpstart and We use disksuite for mirroring the operating system drives.
    Primary Server     Recovery Server
    Sun Fire 6800     Sun Fire E2900
    Sun Fire E2900     Sun Fire 6800
    Sun Fire-880     Sun Fire-V440
    Sun Fire-V440     Sun Fire-880
    Sun Fire 4800     Sun Fire-880
    Sun Fire-V890     Sun Fire 4800          
    Me

    jds2n,
    Is it possible to get around installing the Entire Distribution + OEM and include only the platform specific files?
    Just a thought
    Example:
    I would like to create a Flash Archive of a E2900 server which i plan to use to recover a 6900.
    The 2900 was installed with a developer cluster.
    When creating the Flash archive of the 2900 is it possible to add the 6900 platform specific files and drivers
    from the Solaris CD?
    Thanks

  • I need help with printing labels.  please

    I need help with printing labels.  thanks in advance

    Welcome to Apple Support Communities.
    In Address Book, first select a name or group of names to print.
    Then File, Print, select Style, Mailing Labels, then Layout to select a specific target label (such as an Avery number), or define your own...

  • I need help with the https class please.

    Hello, i need add an authentication field in my GET request using HTTPS to authenticate users. I put the authentication field using the setRequestProperty method, but it doesn't appear when i print all properties using the getRequestProperties method. I wrote the following code:
    try{
    URL url = new URL ("https://my_url..");
    URLConnection conexion;
    conexion = url.openConnection();
    conexion.setRequestProperty("Authorization",my_urlEncoder_string);
    conexion.setRequestProperty("Host",my_loginServer);
    HttpsURLConnection httpsConexion = (HttpsURLConnection) conexion;
    httpsConexion.setRequestMethod("GET");
    System.out.println("All properties\r\n: " + httpsConexion.getRequestProperties());
    }catch ....
    when i run the program it show the following text:
    All properties: {Host=[my_loginServer]}
    Only the Host field is added to my HttpsURLConnection. The authentication field doesnt appear in standar output. How can i add to my HttpsURLConnection an Authentication field?
    thanks

    I have moved this to the main Dreamweaver forum, as the other forum is intended to deal with the Getting Started video tutorial.
    The best way to get help with layout problems is to upload the files to a website and post the URL in the forum. Someone can then look at the code, and identify the problem. Judging from your description, it sounds as though the Document window is narrow, which would result in the final menu tab dropping down to the next row. Try turning on Live view or previewing the page in a browser. Design view gives only an approximate idea of the final layout. Live view renders the page as it should look in a browser.

  • Need Help with Migration...Please

    Hello,
    I need help!  I just bought a new MacBook Pro.  In house, I have a two year old iMac running Mavericks (all updated) and an iPhone and iPad (both running the most current OS).  I also have the iMac connected to a Time Capsule.  Here are my questions:
    1.  As I am not replacing the iMac, but rather adding a MacBook Pro to the mix, should I migrate the software, settings, files, etc. from the iMac to the MacBook?  Is there an issue running computers which are clones in the same environment?  Is it a bad idea to migrate?
    2.  Assuming # 1 is okay to migrate, what is the best way?  Is it best directly from the iMac or from the Time Capsule?  I do have a Thunderbolt to Ethernet adapter on hand. 
    3.  Is there a link that would help me navigate the migration?
    4.  How long should the migration in #2 take?
    5.  Will I need to change any settings on the iMac, iPhone, or iPad afterwards?
    6.  Will my contacts and calendar sync with iCloud automatically, or do I have to change a setting on the MacBook to make that happen?
    7.  Also, as I'm leaving town tomorrow and want to take the MacBook Pro with me and I'm unsure I've the time to Migrate and tweak, can I jus turn on the MacBook (still not turned on), use it as it is, and then migrate when I get back home?
    Any help would greatly be appreciated.  Thank you!

    Hello,
    I need help!  I just bought a new MacBook Pro.  In house, I have a two year old iMac running Mavericks (all updated) and an iPhone and iPad (both running the most current OS).  I also have the iMac connected to a Time Capsule.  Here are my questions:
    1.  As I am not replacing the iMac, but rather adding a MacBook Pro to the mix, should I migrate the software, settings, files, etc. from the iMac to the MacBook?  Is there an issue running computers which are clones in the same environment?  Is it a bad idea to migrate?
    2.  Assuming # 1 is okay to migrate, what is the best way?  Is it best directly from the iMac or from the Time Capsule?  I do have a Thunderbolt to Ethernet adapter on hand. 
    3.  Is there a link that would help me navigate the migration?
    4.  How long should the migration in #2 take?
    5.  Will I need to change any settings on the iMac, iPhone, or iPad afterwards?
    6.  Will my contacts and calendar sync with iCloud automatically, or do I have to change a setting on the MacBook to make that happen?
    7.  Also, as I'm leaving town tomorrow and want to take the MacBook Pro with me and I'm unsure I've the time to Migrate and tweak, can I jus turn on the MacBook (still not turned on), use it as it is, and then migrate when I get back home?
    Any help would greatly be appreciated.  Thank you!

  • I need help with my new tablet please !

    hi there
    i cant logon the appworld in my tablet
    iam from Saudia arabia
    it says " the app world not available in my country "
    how can i install app if i cant conect from my tablet
    is there any way to use my laptop for help
    iam using MACBOOK computer
    in case if there is any programme need to download
    so i can work with my tablet
    sorry for my bad english
    with all respect
    Nawaf

    Dear friend, by the moment Blackberry playbook is just for USA/Canada users, in a very short time RIM will announce the release of the product for the rest of countries.
    Be patient when you can use it at 100%, you will be amazed!

  • I need help with my wifi sync, please?

    I am trying to sync a single band from my laptop to my iPhone. This is my new laptop and I have no transfered all my music from my old computer onto here, so I can not sync through the cable or else I will have to remove all my exsisting information on my phone, I do not have all my music on my laptop yet. All I want is to simply transfer a few songs from my iTunes to my phone wirelessly and I can't. I enabled the button when I plug in my phone that tells me I can sync wirelessly but when I disconnect it refuses to work. Please I need help.

    Dear friend, by the moment Blackberry playbook is just for USA/Canada users, in a very short time RIM will announce the release of the product for the rest of countries.
    Be patient when you can use it at 100%, you will be amazed!

  • I just bought my MacBook Pro 13" and I tried to install an anti virus but then it went into a grey folder with a question mark I need help with restoring the iOS please

    I need help taking out the grey folder with the question mark and I've try everything except the CD thing because my MacBook didn't come with one so I really need help please

    What anti-virus software did you install? Although there's a lot of bad anti-virus software out there, no anti-virus software should cause such a problem. A gray screen with a flashing question mark on a folder means that no bootable system could be found, which means that the system was badly damaged or corrupt. Even installing bad software would not normally cause that, so either there was something badly wrong with the system already or the anti-virus software you tried to install was really, really bad!
    As mende1 says, you need to reinstall the system at this point. After your system is back up and running, read my Mac Malware Guide. If, after reading that, you want anti-virus software, use one of the programms recommended in that guide.

  • Need help with using Email Activation Agent

    Hi,
    please, help me with using E-mail Activation Agent.
    I used email activation agent to start business processes by email, but after that letter disappear from email-server.
    Where letter was located?
    Can I get and read letter for processing?

    Mail/Preferences/General - do you have Unibox set as your default e-mail application?

  • Help with JSP / Static methods in beans...

    Hi:
    I am creating several javabeans as part of my application. Is it ok, to make all of them static (no global variables are used) and access in JSP's and Servlets as XXBean.method(var1, var 1). Is this a problem ? (vs creating a new XXBean and using it in every page/servlet).
    I have gut feeling that static methods are better and give better memory usage and performance - as oppose in other scenario I am creating a new Bean for every page access - could not verify. and not sure not creating (new Bean) would give any problems.
    Thanks for sharing.

    No, static methods are not what you want. Just set the "scope" on your use-bean tag to "application".
    <jsp:useBean id="xbean" class="xpackage.XXBean" scope="application" />Alternatively, if what you are trying to do is a pure "function library", then create a tag lib, and add the function definitions like this:
    <function>
         <name>someMethod</name>
         <function-class>xpackage.XXBean</function-class>
         <function-signature>
         java.lang.String someMethod( java.lang.String )
         </function-signature>
    </function>There is a fairly concise description of how to do this at
    http://java.boot.by/wcd-guide/ch07s04.html

Maybe you are looking for