JSP Sending textbox info from one page to another

I am a java, c++/# programmer I don't know html very well
I am firmiliar with sessions and I am using one on this project

I have a jsp file that populates book titles from a db and in a text box a user can enter a number to order

I have to send that info (book title and qty) to a new page in a session (So I can add more books from other publishers) or goto a "Check out" area
here is what I am trying:

<html><head><title>A Simple Test of Database Connection</title></head>
<body bgcolor="wheat" text="black" link="darkgreen" vlink="steelblue" alink="darkblue">
<font size="+2">A Listing Of Publishers</font>
<br><br>
<%@ page import="java.sql.*" %>
<table border=1>
<form action="page3.jsp"  method="post">
  <%
  try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn = DriverManager.getConnection("jdbc:odbc:Books", "anonymous", "guest");
   
    String publisher = request.getParameter("Publisher");
    java.sql.Statement statement = conn.createStatement();
   
    String sql = "select * from Titles where PublisherID = " + publisher;
   
    ResultSet resSet = statement.executeQuery(sql);
   
    while (resSet.next()) {
          String title = resSet.getString("Title");
   
           out.print("<br>" + resSet.getString("ISBN") + " " + title);
           out.print("   <input type = \"text\" name = \"title\" size = \"5\">" );
          
    }
   
     } catch (Exception e) {
    out.print("<br> Error, database connection: " + e);
  }
  %>
  <p><input type="submit" name="more" value="Back to add more Publishers">
<p><input type="submit" name="Done" value="Goto Finalize order Page">
<p><input type="reset" name="reset" value="Cancel Order">
  </form>
</table>
</body>
</html>


what I need to know is how do i set up the dynamic text box to send the value of a title that matches a qty into a session to be able to fill out a check out
Being a student and i need to finish this by mid teusday april 19


 
Socrates2k1Asked:
Who is Participating?
 
RozanaZConnect With a Mentor Commented:
You may create hidden field that will contain info about book title, this field won't be visible but it's value will be passed with other values:

<input type="hidden" name="book_title" id="book_title" value="<%=bookTitle%>">
0
 
bloodredsunConnect With a Mentor Commented:
What you need to do is submit the form which puts the information into the request parameters, these are accessable by calling request.getParameter(name) if you know the names, or getParameterNames() if you don't know the names in page3.jsp (the taget of your action attribute in the form). You can then iterate over the enumeration returned from getParameterNames() to find the quantity associated with each title. Then once you have this, you can easily put them into the session, either directly using session.setAttribute("War and Peace" , "5"); or a better idea would be create a shopping cart object whcih you then put into the session.

I'm not sure that having a hidden field will help you as you still have to associate the title of the book with the quantity.

I'm sorry but as this is a graded assignment I can't give you the complete codes as this violates the EE member agreement.

Good luck and happy coding.
0
 
neu-rahConnect With a Mentor Commented:
usually i make each item of the list as a link
ex:
   secondpage.asp?id=.....  //<--- where i print ids of them to diferenciate the links
   out.print("<br><a href='secondpage.asp?isbn=" + resSet.getString("ISBN") + "'>"+...+"</a>"... or something like that

this method wont let you submit a user choosed qty.. so i sugest you elaborate a bit more your listing and instead of simple links, do a <form> for each element in the list, and there you can use hidden fields

this solution requires a submit button for each item as each one is an independent form

both methods will generate the same kind of submit (1 item) ex: secondpage.asp?isbn=xxxxxxx
with secondpage.asp?isbn=xxxxxxx&qty=n for the item forms

there are a lot of other processes more elaborated then these ones... like a shop-cart... its up to you to choose
a diferent aproach is taken here, parameters on the submit gota be something like:
secondpage.asp?isbn1=5&isbn2=3&...
one submit can transact several items... as you have not required this i wont go further
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.