| | |
Get Parameter value
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 34
Reputation:
Solved Threads: 0
For my Java class with resultset I am trying to get the request.getParameter value.
Please advise if this is the correct way use the request object in a Java class because I cant seem to get any data from the request object.
Please advise if this is the correct way use the request object in a Java class because I cant seem to get any data from the request object.
Java Syntax (Toggle Plain Text)
... import javax.servlet.*; import javax.servlet.http.*; ..... HttpServletRequest request = null; String cityEntry = request.getParameter("city"); try{ Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from cityTable where city = 'Boston'"); while (rs.next()) { String city = rs.getString("city"); if(cityEntry.equals(city)) { //do something... ............... }
•
•
Join Date: Aug 2006
Posts: 137
Reputation:
Solved Threads: 11
I'm not sure why you said 'no,' sillyboy? But yes, since chicago1985 instantiated the object to null, there wouldn't be anything to 'get.'
What concerns me is that he actually declared the variable request. I'm assuming the class this method belongs to, is a servlet? That is, the class extends javax.servlet.http.HttpServlet... please confirm this. If it is a servlet then you'd have access to the request object via the doGet and doPost methods. Depending on how you send information to the servlet, one or both methods are applicable.
The request object is the HttpServletRequest object found in the parameter of either mentioned method. Hope this helps.
What concerns me is that he actually declared the variable request. I'm assuming the class this method belongs to, is a servlet? That is, the class extends javax.servlet.http.HttpServlet... please confirm this. If it is a servlet then you'd have access to the request object via the doGet and doPost methods. Depending on how you send information to the servlet, one or both methods are applicable.
The request object is the HttpServletRequest object found in the parameter of either mentioned method. Hope this helps.
•
•
Join Date: Nov 2007
Posts: 34
Reputation:
Solved Threads: 0
•
•
•
•
I'm not sure why you said 'no,' sillyboy? But yes, since chicago1985 instantiated the object to null, there wouldn't be anything to 'get.'
What concerns me is that he actually declared the variable request. I'm assuming the class this method belongs to, is a servlet? That is, the class extends javax.servlet.http.HttpServlet... please confirm this. If it is a servlet then you'd have access to the request object via the doGet and doPost methods. Depending on how you send information to the servlet, one or both methods are applicable.
The request object is the HttpServletRequest object found in the parameter of either mentioned method. Hope this helps.
•
•
Join Date: Aug 2006
Posts: 137
Reputation:
Solved Threads: 11
Hmmm, so you're developing a web application using JavaEE hey? So depending on whatever the user typed in web form, you want to search for a matching city... then the SQL statement you have will not work unless the user typed in 'Boston.' Do you understand why this is so?
Even thought this is a helper class, it must be spawned from the servlet because there is no other way (that I know of) to access the web application object request. If this is so, then simply pass on the request object from the servlet to the helper class (probably via the constructor). Does this make sense? It's crucial that you understand what the request object is and why it's only accessible via the doPost and doGet methods. Remember that when you submit the form (in your JSP file?), you can choose whether to submit it using the POST or GET method.
Even thought this is a helper class, it must be spawned from the servlet because there is no other way (that I know of) to access the web application object request. If this is so, then simply pass on the request object from the servlet to the helper class (probably via the constructor). Does this make sense? It's crucial that you understand what the request object is and why it's only accessible via the doPost and doGet methods. Remember that when you submit the form (in your JSP file?), you can choose whether to submit it using the POST or GET method.
![]() |
Similar Threads
- Parameter error for executeNonQuery() (VB.NET)
- Jsp doesnt return parameter value (JSP)
- How can i find out a parameter's type? (C++)
- unfamiliar parameter specified (C)
- Command Line Parameter (C++)
Other Threads in the Java Forum
- Previous Thread: Quick Search(Finding Duplicate Records)
- Next Thread: Action listener
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





