| Author |
take parameters in jsp and put in select sql
|
Tatiana Schineider
Greenhorn
Joined: Aug 06, 2010
Posts: 16
|
|
Hello,
I'm trying to get a value of my parameter, but can not.
I know when I send the content to show it, is normal, for example:
I'm trying to put the contents of it to this query
Does anyone have any idea?
thank you
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 13842
|
|
|
The best idea would be to not do it in a JSP. Do it in a servlet, or something else which is naturally Java code. And for the JDBC part of the question, a PreparedStatement with a ? parameter would be the best choice.
|
 |
Epifanio Guzman
Greenhorn
Joined: Jun 24, 2008
Posts: 16
|
|
:wink: i think this is already resolved.
But here's my answer. Maybe it could be helpful for someone.
Like Paul, i think it should be in a class.
1.- jsp
send param using text fiel, in FORM:
<input name=\"txtStrGeneric1\" type=\"text\" id=\"txtStrGeneric1\"></td> \n";
using param:
url ..... +"&StrGeneric1="+StrGeneric1;
2.- jsp
get param from text fiel.
try{StrGeneric1 = request.getParameter("txtStrGeneric1");}
catch(Exception e){}
get param from a param.
try{StrGeneric1 = request.getParameter("StrGeneric1");}
catch(Exception e){}
3.- in JSP
using StrGeneric1 whit value
AClass obj = new Aclass();
obj.setStrGeneric1 (StrGeneric1);
Listcc = obj.getListOfSelect(); //when ends 4.-
4.- the class AClass
db_Local <--- a SQL class
using code like:
java.sql.PreparedStatement pstmt= db_Local.Connection.prepareStatement ("select * from Table where StrGeneric1=?");
pstmt.setString (1,Value);
pstmt.executeUpdate();
--->return a List for example.
5.- JSP
iterate the list.
show data to client browser.
:thumbup: This is only like reference, there are many frameworks to do the job.
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50693
|
|
|
As Paul has said, this has no place in a JSP. The practice of putting Java code into a JSP has been discredited for 10 years now. 10 years! Any advice that has you put Java code into a JSP is bad advice.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: take parameters in jsp and put in select sql
|
|
|