Results 1 to 9 of 9
- 04-24-2012, 10:16 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
pass a parameter from sql table to jsp page.
im new to jsp. i ve a table, that i can view easily on browser using jsp. now i want to pass only 1 value of a particular column on click. i tried assigning a parameter to that value and directing its action to main page where im storing that parameter in a string with request.getParameter ("parameter"). but when im passing this string to fetch values in the table, im getting null. plz help..
im passing parameter like
<td> <input name="<portlet:namespace />cid" value= "<%=rst.getString("ID")%>"/></td>
and retrieving it in details page as:
String id= request.getParameter("cid");
i want to use this id to fetch values from table as below:
String s1 =("SELECT SMILES FROM CHEMICAL_LIBRARY WHERE ID= '"+id+"'" );
....
im getting a null value. but a correct result if i pass id manually like 1 or 2. all connections and drivers are ok. the problem is in passing the parameter. plz help
- 04-24-2012, 12:29 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: pass a parameter from sql table to jsp page.
What does the html for that input field look like on the client?
Also, it's not a good idea to do database interaction in your JSP. You ought to go via a servlet, whose job is to get the data needed by the JSP and then forward.
It would be a lot easier to debug that way.Please do not ask for code as refusal often offends.
- 04-25-2012, 06:08 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
pass a parameter from sql table to jsp page.
thanks 4 the reply!!
the page showing the database looks like this:

when i click view button, i want that particular value in SMILES column to be passed. i gave a parameter name to id value while retrieving it from database and passed it to the final page. in the final page after storing the value in a string as request.getParameter("parameter"), im passing this in SQL statement as "SELECT SMILES FROM CHEMICAL_LIBRARY WHERE ID= '"+id+"'" ); but im getting null value. if manually i pass id values like 1, 2 etc, im getting desired results. il definitely try it via servlet, once i get the actual concept.
- 04-25-2012, 09:29 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: pass a parameter from sql table to jsp page.
No, I asked for the HTML for that field, not a picture of the page in the browser.
Also, are you saying that 'id' is null on the server? That is, 'request.getParameter("cid")' returns null?Please do not ask for code as refusal often offends.
- 04-25-2012, 11:43 AM #5
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: pass a parameter from sql table to jsp page.
the HTML is like this:
<html>
<body>
<link rel="stylesheet" type="text/css" href="style.css" />
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><B>Id</B></td>
<td><B>SMILES</B></td>
<td><B>Chemical name</B></td>
<td><B>IUPAC</B></td>
<td><B>MOL_Formula</B></td>
<td><B>Mol_Mass(g/mol)</B></td>
<td><B>Use</B></td>
</tr>
<% while(rst.next())
{
%>
<tr>
<td>
<input name="cid" value= "<%=rst.getString("ID")%>"/> </td>
<td><%=rst.getString("SMILES")%>
<form method="post" action="view.jsp">
<input type="submit" value="view"/>
</form></td>
<td> <%=rst.getString("CHEMICAL_NAME")%></td>
<td> <%=rst.getString("IUPAC")%></td>
<td> <%=rst.getString("MOL_FORMULA")%></td>
<td> <%=rst.getString("mol_mass(g/mol)")%></td>
<td> <%=rst.getString("USE")%></td>
<%} %>
</tr>
</table>
</body>
</html>
yes im getting a null value when im passing "cid" parameter as 'request.getParameter("cid")' in final page.
- 04-25-2012, 12:08 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: pass a parameter from sql table to jsp page.
That's not the html on the client.
What does the source for that input tag look like on the client.
Indeed the whole form.
In fact, saying that...that tag is not in the form, so of course it's not going to be submitted.Please do not ask for code as refusal often offends.
- 04-25-2012, 12:42 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: pass a parameter from sql table to jsp page.
ya thanku so much i got it.. i was not including this parameter in the form.. thanks!
- 04-25-2012, 12:50 PM #8
Re: pass a parameter from sql table to jsp page.
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-31-2012, 09:32 AM #9
Member
- Join Date
- Mar 2012
- Posts
- 41
- Rep Power
- 0
Re: pass a parameter from sql table to jsp page.
Do you connect to the database during view.jsp processing???
you create a statement too?? and get DriverManager .... e.t.c
then return a ResultSet???
Then you assign put() a property onto view.jsp (beats me why you don't take the field value from the ResultSet and put it into a "global variable" if the JSP code is in your JSP page)
note: view.jsp should appear like
view.jsp?cid=whatever+goes+here%20or%20here
Similar Threads
-
Unable to pass parameter to servlet through JSP
By nn12 in forum New To JavaReplies: 1Last Post: 03-11-2011, 01:55 PM -
how to pass value of table cell as parameter/attribute
By ajincoep in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 02-08-2011, 03:04 PM -
how to pass parameter from one jsp to another jsp
By kader_sit in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 06-10-2010, 02:04 PM -
I can't seem to pass a file through a parameter
By daletron3030 in forum New To JavaReplies: 5Last Post: 01-15-2009, 06:07 AM -
How to pass mysql string through a url parameter to a detail page query
By kwesiaryee in forum New To JavaReplies: 1Last Post: 08-22-2008, 06:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks