JSP Sending textbox info from one page to another

Posted on 2005-04-18
Medium Priority
Last Modified: 2012-06-27
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>
<%@ page import="java.sql.*" %>
<table border=1>
<form action="page3.jsp"  method="post">
    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">

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

Question by:Socrates2k1

Accepted Solution

RozanaZ earned 672 total points
ID: 13812986
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%>">
LVL 29

Assisted Solution

bloodredsun earned 664 total points
ID: 13813784
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.

Assisted Solution

neu-rah earned 664 total points
ID: 13816077
usually i make each item of the list as a link
   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:
one submit can transact several items... as you have not required this i wont go further

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question