Results 1 to 9 of 9
  1. #1
    kirti bansal is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default 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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,757
    Rep Power
    19

    Default 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.

    ** This space for rent **

  3. #3
    kirti bansal is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Exclamation pass a parameter from sql table to jsp page.

    thanks 4 the reply!!
    the page showing the database looks like this:

    pass a parameter from sql table to jsp page.-view.jpg
    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.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,757
    Rep Power
    19

    Default 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.

    ** This space for rent **

  5. #5
    kirti bansal is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: pass a parameter from sql table to jsp page.

    Quote Originally Posted by Tolls View Post
    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?


    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.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,757
    Rep Power
    19

    Default 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.

    ** This space for rent **

  7. #7
    kirti bansal is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default 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!

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: pass a parameter from sql table to jsp page.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    nicephotog is offline Member
    Join Date
    Mar 2012
    Posts
    41
    Rep Power
    0

    Default 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

  1. Replies: 1
    Last Post: 03-11-2011, 01:55 PM
  2. how to pass value of table cell as parameter/attribute
    By ajincoep in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-08-2011, 03:04 PM
  3. how to pass parameter from one jsp to another jsp
    By kader_sit in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-10-2010, 02:04 PM
  4. I can't seem to pass a file through a parameter
    By daletron3030 in forum New To Java
    Replies: 5
    Last Post: 01-15-2009, 06:07 AM
  5. Replies: 1
    Last Post: 08-22-2008, 06:28 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •