Request.getParameter("blah") from within a class?

Hi Everyone,
Not sure if I'm missing something...
I'm trying to create a class that will examine and parse information from a form, and then pass it to another class that knows how to handle the input.
A request in the form of http://www.domain.com/stuff.jsp?1=param1&2=param2&4=param4
stuff.jsp only has this:
UrlRequestGetter params = new UrlRequestGetter();
out.println(params.getTheParams());and the general idea for the UrlRequestGetter class is this:
public classUrlRequestGetter {
     public String getTheParams(){
          String request1 = request.getParameter("1");
                String request2 = request.getParameter("2");
                String request3 = request.getParameter("3");
                String request4 = request.getParameter("4");
}Within that class, there will be various actions to check whether or not fields are empty, etc. The big point is that i'm trying to do a request.getparameter from within a class. When i try to compile, I get:
cannot find symbol
symbol:variable request
Any thoughts?
Thanks!

Take a step back from all that, and read the error message: cannot find symbol: symbol:variable request
Is "request" a variable you have declared or passed into your method getTheParams() ?
Where is it supposed to get the request from?
"request" is an implicit variable to your JSP. If you want to use it in your bean, you have to pass it as a parameter.
I'm trying to create a class that will examine and parse information from a form, and then pass it to another class that knows how to handle the input.You might consider using the <jsp:setProperty> tag to map parameters to bean attributes automagically.
Or the BeanUtils.populate method provided by Jakarta Commons BeanUtils.
Or any framework like struts, jsf, spring, stripes....
Cheers,
evnafets

Similar Messages

  • Using System.err.println() from within the classes of WAS ?

    hi,
    I am using admin.jar,a jar file which is being used by Web Application Server in my own class.
    I am referencing some of the classes from admin.jar from my class.
    I tried to print some trace statements,using System.err.println() from within the classes in admin.jar but they did not reflect in defaulttrace0.trc.
    I made these changes in the admin.jar being used by WAS.
    I restarted the server and even restarted the machine but without success.
    I want to know how to print System.out.println() statements from within the classes in admin.jar.
    Also, am i looking for these statements in the right file for eg. defaulttrace0.trc. or is it some other file that i need to look into.
    I need urgent help on this.
    Reward points assured.
    thanks a lot.
    Saurav

    thanks craig,
    ur answer has helped me a lot.but it didnt quite help me.
    nevertheless i am trying to set different levels of severity.
    Is there anything else that i can do.
    Also,i commented out a line of code today in one of the class DataSourceManagerImpl.java in sapj2eenginedeploy.jar
    for eg. temp.delete in it deploy method.Buth that line still executed.
    I m totally lost as to wht to do.
    I m trying to create a datasource from my application in WAS.For that i m using the WAS APIs.But its not working completely.
    I am using the above jar and its method createdatasource.
    I am callin it from my application's class.
    It creates a datasource and i can see it in JDBC Connector list in Visual Administrator.But it appears with red sign meaning its not started.When i start it from the tool then it starts.
    But in defaulttrace.trc file it shows an error "FileNotFindException". This happens,and i am very much sure, in the deploy() of DataSourceManagerImpl.java class of sapj2eenginedeploy.jar.
    i want to apply println inside this method so i may know where exactly i ma getting the error and get so more info so i may solve my problem.
    pls help me.
    its really urgent.
    thanks again
    saurav

  • Reading files from within helper classes

    From within a servlet, I can get the servlet context to get a path to the "web" directory of my project and easily access properties files for my project. If I create another package in my project to hold helper classes that perform some specific function and want to create and/or read from a properties file, I get a path to the bin directory of my servlet container:
    Servlet Path: D:\Documents and Settings\Josh\My Documents\Josh\Projects\ServletSandBox\build\web\
    Helper Class File Path: D:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.14\bin\test
    I'd like to develop my helper packages as reusable APIs, so they're not tied directly to my project or to a servlet in general, but I'd like the properties files to stay somewhere in my project folder, preferably in the WEB-INF directory with the servlet's own specific properties file.
    I can't figure out the best way to handle this. I wanted to just be able to pass the helper class a String if somebody wanted to specify a filename other than the default filename. Does it make sense to specify a file URL instead? Is there any other way to get the calling servlet's context path without having to pass in a variable?
    Thanks

    It seems that the helper API shouldn't need to be given a path to its own config file. I would like to have code that will load the file regardless of whether or not its in a stand alone java app or a servlet. Whenever the helper API is jarred up and imported into my servlet, it can't find the config file unless it's in the "D:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.14\bin\test" directory. OR, if I use the current thread to get the loader, it will locate it in the "classes" folder, which is the only solution I can come up with that will let me write code to load the file that will work, regardless of its implementation.
    The "project" folder I'm talking about is just the NetBeans "project" folder for the servlet, or the "ServetSandBox" folder in my example. I guess that doesn't really matter in the context of the servlet though.
    So is using the current thread the appropriate way to do this? When you say that code will work if I put the resource in the WEB-INF directory, that seems to only be true if I try to load it from the servlet itself, not the helper class. The helper class doesn't find the resource in the WEB-INF directory.
    Also, I would like to be able to write the default values to a new config file if one doesn't exist. How in the heck do I get a pointer to the "classes" folder, or any other folder that I can also read from using the classloader, so I can write to a new file?

  • Calling a java application from within another class

    I have written a working java application that accepts command line parameters through public static void main(String[] args) {} method.
    I'm using webMethods and I need to call myapplication from within a java class created in webMethods.
    I know I have to extend my application class within the webMethods class but I do not understand how to pass the parameters.
    What would the syntax look like?
    Thanks in advance!

    why do you want to call the second class by its main method ??
    Why not have another static method with a meaningfull name and well defined parameters ?
    main is used by the jvm as an entry point in your app. it is not really meant for two java applications to communicate with each other but main and the code is not really readable.
    Have a look at his sample
    double myBalance = Account.getBalance(myAccountId);
    here Account is a class with a static method getBalance which return the balance of the account id you passed.
    and now see this one, here Account has a main method which is implemented to call getBalance.
    String[] args = new String[1];
    args[0] = myAccountId;
    Account.main(args);
    the problem with the code above is
    main doesn't return anything so calling it does do much good. two the code is highly unreadable because no one know what does the main do... unlike the sample before this one where the function name getBalance clearly told what is the function doing without any additional comments.
    hope this helps.... let me know if you need any additional help.
    regards,
    Abhishek.

  • Feuture Request: Open Acrobat from within Reader

    Many people will recognise this: sometimes you just need reader to open invoices, web documents, etc. Sometimes you work with Acrobat a lot. Now you can switch the default program to open pdf's every time, but that's a hassle. Why isn't there (as far as I can see and I googled quite some time) a button in Reader that says: "Open this document in Acrobat"? I guess this would save millions of people a lot of hassle.
    Its eems so obvious that I cannot imagine another request has been made for this, but I couldn't find it, so here it is. If I overlooked something, please point it out.

    You cannot choose which program to open a PDF with when it is online or in an email. Which 95% of the PDF's one opens for just reading, in general are. Those other 5% are no problem, I agree.
    Acrobat is uses much more system resources and takes much longer to start than Reader. (Also I mostly disable the  the system startup time slurping Adobe "helpers" from Windows startup since I do not use Acrobat much, except for one month in a year when I work on printing matter. This makes startup time for every day use even longer.) I have a pretty fast computer, but for people with slower computers this is even more a real issue.
    Anyway, every user is different and has his reasons to do things this way or that way. Users who prefer Reader for everyday use, but sometimes need Acrobat;s function, for instance for OCR-ing, - which you often do not know that you will need at the time of opening - would benefit much from this simple feature.

  • Creating an instance of a class from within another class

    I am trying to create an instance of MCQ in the T class but I am getting this error:
    File: E:\JAVA PROGRAMS\assignment 1\T.java [line: 15]
    Error: cannot find symbol
    symbol : class MCQ
    location: class T
    here are the two classes:
    // class T
    import java.awt.*;
    import java.util.*;
    import java.lang.*;
    public class T{
    public T(String aT)
    pest = aT;
    public static T t_one()
    T aT = new T("Calculator");
    aT.addQ(new MCQ( " 2 + 2", "equals 4", "equals 5", "equals 0", " equals -2",
    "is a prime number", 1));
    return aT;
    private String pest;
    //class Q
    import java.awt.*;
    import java.util.*;
    import java.lang.*;
    public abstract class Q{
    Vector q = new Vector();
    public String aT;
    abstract void addQ(Q aQ);
    public class MCQ extends Q{
    String a,b,c,d,e,f,g;
    int answer;
    public MCQ (String a, String b, String c, String d, String e, int answer)
    this.a = a;
    this.b = b;
    this.c = c;
    this.d = d;
    this.e = e;
    this.answer = answer;
    void addQ(Q aQ)
    q.addElement(new T(aT));
    I tried to make reference to MCQ by doing this in class T:
    MCC qT = new MCQ() ;
    but that presents a whole other set of problems.
    please help I think I have tried everything!

    Use code tags (http://forum.java.sun.com/help.jspa?sec=formatting)
    Don't import java.lang.* . You get those automatically.
    Your MCQ class is really Q.MCQ (the way you posted, anyway).
    If Q weren't abstract, you could do:
    new Q().new MCQ(...)But, you can't create a Q without defining 'add'. You could do it anonymously, but that makes no sense. Put Q and MCQ in separate files and try again.

  • How to reach a method of an object from within another class

    I am stuck in a situation with my program. The current situation is as follows:
    1- There is a class in which I draw images. This class is an extension of JPanel
    2- And there is a main class (the one that has main method) which is an extension of JFrame
    3- In the main class a create an instance(object) of StatusBar class and add it to the main class
    4- I also add to the main class an instance of image drawing class I mentioned in item 1 above.
    5- In the image drawing class i define mousemove method and as the mouse
    moves over the image, i want to display some info on the status bar
    6- How can do it?
    7- Thanks!

    It would make sense that the panel not be forced to understand its context (in this case a JFrame, but perhaps an applet or something else later on) but offer a means of tracking.
    class DrawingPanel extends JPanel {
      HashSet listeners = new HashSet();
      public void addDrawingListener(DrawingListener l) {
         listeners.add(l);
      protected void fireMouseMove(MouseEvent me) {
         Iterator i = listeners.iterator();
         while (i.hasNext()) {
            ((DrawingListener) i.next()).mouseMoved(me.getX(),me.getY());
    class Main implements DrawingListener {
      JFrame frame;
      JLabel status;
      DrawingPanel panel;
      private void init() {
         panel.addDrawingListener(this);
      public void mouseMoved(int x,int y) {
         status.setText("x : " + x + " y: " + y);
    public interface DrawingListener {
      void mouseMoved(int x,int y);
    }Of course you could always just have the Main class add a MouseMotionListener to the DrawingPanel, but if the DrawingPanel has a scale or gets embedded in a scroll pane and there is some virtual coordinate transformation (not using screen coordinates) then the Main class would have to know about how to do the transformation. This way, the DrawingPanel can encapsulate that knowledge and the Main class simply provides a means to listen to the DrawingPanel. By using a DrawingListener, you could add other methods as well (versus using only a MouseMotionListener).
    Obviously, lots of code is missing above. In general, its not a good idea to extend JFrame unless you really are changing the JFrames behavior by overrding methods, etc. Extending JPanel is okay, as you are presumably modifiying the drawing code, but you'd be better off extending JComponent.

  • Problem executing .bat file from within Java class

    I'm stumped: I have no problem executing a .bat file that sets classpaths and executes a Java jar, but when I try to execute other executables first and then the .jar, my application hangs and since the DOS box doesn't come up over my GUI, I can't see what's going on.
    This works:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\omni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat 'omni.bat'
    set JAVA_HOME=c:\j2sdk1.4.2_04\bin
    %JAVA_HOME%\java -jar C:\CS47AUXS\OMNILOADJAR\OmniLoad.jar
    This doesn't work:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\jobomni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat file 'jobomni.bat'
    SET NETX_HOME=C:\CS47AUXS
    SET COBOL_HOME=C:\CS47AUXS\OFFLINE
    CD %NETX_HOME%
    CALL SET-NETX.CMD
    CD %COBOL_HOME%
    SSBPPC10 JOBOMNI X
    SET JH=C:\J2SDK1.4.2_04\BIN
    SET OMNI_HOME=C:\CS47AUXS\OMNILOADJAR
    CD %OMNI_HOME%
    %JH%\java -jar omniload.jar
    Can anyone shed some light here? Even when I execute the application from the command line the new DOS box doesn't become visible nor can I see any errors. If I could just get that visibility, I could probably figure out what is going wrong.

    Same problem with me as well.... Badly looking for a solution...
    I predict the following:
    - If your batch file has pretty less number of dos/shell commands then it gets executed fine with exec() and proc.waitFor();
    - If you increase the number of dos/shell commands in the bat file then try executing it then it definately hangs at proc.waitFor();
    Even "cmd.exe /C C:\\test.bat" hangs... if the commands are more...
    Is this some sort of bug? or am i doing anything wrong? I tried searching for solution on the net and search forums... but couldnt find a solution for the same.. not sure where i missed, what i missed...
    Incase some one finds a solution.. do post it here...
    Message was edited by:
    amadas

  • How to find path from within java class where .class file is located

    I have a situation where my Servlet is running.
    I need to access a text file which is locted in the same
    place where the .class file for this Servlet is located.
    I cannot specify absolute path in my java file.
    I am in Windows platform.
    My filename is specified as
    File("myfile.txt");
    the problem is it says file not found.
    how do i fix this prob?
    thanks in advance

    String filename="/relative_path/file_name.txt";
    try {
       //static method approach
       InputStream is = YourClassName.class.getResourceAsStream(filename);
       //non-static method approach
       InputStream is = getClass().getResourceAsStream(filename);
    } catch (IOException e) { ... }tajenkins

  • No access to method from within the same class

    Hey there.
    First I have to excuse my English for I'm german and just learning...
    Ok, my problem is as follows. I have a class called JDBC_Wrapper it includes the method sendQuery(String query). When I call this method from within another class (where 'wrapper' is my instance of JDBC_Wrapper) it works fine. For example:
    wrapper.sendQuery("SELECT * FROM myDataBase");
    But then I have written a method called getNumRows() into my JDBC_Wrapper class.
    This method should send a query through sendQuery(Strin query) but when calling getNumRows() it says: "java.sql.SQLException: [FileMaker][ODBC FileMaker Pro driver][FileMaker Pro]Unbekannter Fehler." (Unbekannter Fehler -> Unknown Exception). What could that be?
    I'm using jdk2 sdk 1.4.2 with BlueJ. My database is Filemaker Pro 6. The ODBC/JDBC connector works fine.
    BerndZack

    This is within my JDBC_Wrapper class:
    public ResultSet sendQuery(String query)
            if(connected)
                try
                    Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet rs = s.executeQuery(query);
                    return rs;
                catch(Exception e)
                    System.out.println(e);
            else
                //System.out.println("There is no connection to the datasource!");
            return null;
    public int getNumRows()
            try
                ResultSet r;
                r = this.sendQuery("SELECT COUNT(*) FROM " + table_name); // At this line the error occurs
                r.next();
                return (int)r.getInt(1);
            catch(Exception e)
                System.out.println(e.getMessage());
                return -1;
    }When I call sendQuery() from within another class it works, but calling getNumRows()
    throws an exception.

  • Change a UI text field from within a Thread

    My program has a thread that's busy churning away. It's a runnable called from within my classes main. The UI element is built by a method in the class.
    If I try to report something from within the thread by doing a myText.setText("success"); I get a crash:
    Exception in thread "Thread-1" org.eclipse.swt.SWTException: Invalid thread access
    followed by a bunch of SWT.error messages related to that line. The field myText is defined globally for the class.
    What is a good way to be able to write stuff to a UI from within a thread? I could do it when the extended Thread was defined within my main() by creating a runnable also in my main() that got called through a syncExec. But I want to keep the main simple.

    edit Noticed you're working with SWT
    #

  • Calling a method within a class form another class(ViewController)

    I am creating an SQL project in XCODE. I have one view. My main view controller is loading the database to a table/array. I want to add another class (with no NIB) just to handle the display of the table in a UITableView. So, I added a skeleton cocoa touch class file to my classes folder to handle this function when parameters change.
    So, in my app delegate, the "applicationdidFinishLaunchingWithOptions" method loads my mainViewController and NIB.  On the "viewDidLoad" method in my mainViewController, I read a URL into an SQLite database and close the database.  Herein lies the problem: I want to call my new class (TableViewHandler) and pass it the array created in the mainViewController and use the array to populate the UITable.
    How do I call a class from within another class (which has no NIB) to populate the table?  Especially if my TableViewHandler has no "viewDidLoad", "viewDidAppear", etc.
    Regads,
    -Kevin

    This is what my exact problem.
    i've created a bean (DataBean) to access the database. i'm having a servlet program (ShopBook). now to check some details over there in the database from the servlet i'm in need to use a method in the DataBean.
    both ShopBook.java and DataBean.java lies in the package shoppack.
    in ShopBook i tried to instantiate the object to DataBean as
    DataBean db = new DataBean();
    it shows the compiler error, unable to resolve symbol DataBean.
    note:
    first i compiled DataBean.java, it got compiled perfectly and the class file resides inside the shoppack.
    when i'm trying to compile the ShopBook its telling this error.
    hope i'm clear in explaining my problem. can u please help me?
    thank u in advance.
    regards,
    Fazli

  • Spawning threads from within a UnicastRemoteObject

    I have a question regarding spawning threads from within a class that extends UnicastRemoteObject. Would it be okay to spawn new thread(s) in the constructor/ remote methods of the class that extends UnicastRemoteObject .? Are there any pitfalls to doing so? Is it against the suggested practice of writing RMI server code?
    rajkumar

    You can do anything you like in the Class that extends URO.
    The classic problem of doing anything within a constructor is that the object under construction may not be available to the threads you are spawning. That is, since the object is not fully constructed, any fields the new threads need may not be available. There have been discussions on this subject in the forums before. You might give a look and see.

  • How to get requested (target) URL from login page jsp.

    Hi,
    How can I get requested (target) URL from within login jsp page where unauthenticated user was redirected.
    IN other words I need to get target URL that user requested before he was redirected to login page.
    In Weblogic there is "j_target_url" session attribute for this purpose.
    Does NetWeaver have analogue?
    Thanks in advance.

    hi Alex,
    NWDS provides Authentication through Pre defined properties,
    We can trap unauthorised user.
    To know more about this,
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4ecd6eb1-0301-0010-61bd-a3d6bee102c0
    thank you

  • Request.getParameter() from same page as HTML form

    I have a jsp page with a form. form contains a textfield, once the user submits the form, i want jsp scriptlet to get the
    value of the user input and carry out processing on it within the same page and give a result.
    problem is the first time the page is loaded, there is an error in the request.getParameter() statement since no form has
    yet been submitted i guess ....
    if i use another page ... it works ... but i want to display the information in the same page ...
    thanks

    I'd like to see an example where you'd get a NullPointerException from the line
    if(request.getParameter("foo") == null)
    but not one from
    if(null == request.getParameter("foo"))
    In either case, the only possibility for a NullPointerException would be if your request variable were null (but this would cause a NullPointerException in either method). Otherwise request.getParameter() returns a null value if the parameter does not exist, but will not throw a NullPointerException.

Maybe you are looking for

  • Error in loading

    hi all       when loading to psa," Error in generating program" occurs .can anybody suggest the possible solution. thank you pradeep

  • Guys I need help with my ipod touch 2nd generation

    Hi guys, My ipod touch is completely freezed! it show on the screen "Your ipod is stopped, Connect your ipod to iTunes" when I connect to iTunes it show this message "your ipod ... can not be connected to iTunes because it has a passcode, please ente

  • Fusion drive questions

    I recently purchased a Mac Pro and would like to make a fusion drive with the TB drive that it came with. I already have a 200g SSD and am wondering if I would be able to utilize the full 200g SSD. From my understanding of the Fusion drive it appears

  • Since numbers 3.1 rendering problem in output

    Since I upgraded to Numbers 3.1 all printed output is no more crispy, it looks like a rendering problem. My Number documents consist of normal text elements and tables, sometimes some charts. Scaling on printout is not activated. On the Mac display t

  • Spry Table works in Firefox but not IE

    I have a Spry table working just fine in Firefox in a site I'm developing: http://www.abenaki.com/newsite/schedule.html, but in IE 6 and 7 it first shows the table, unpopulated, and then disappears altogether. I'm new to Spry and XML... have I done s