JSP Sending textbox info from one page to another

Posted on 2005-04-18
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 ( {
          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
    LVL 8

    Accepted Solution

    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

    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.
    LVL 1

    Assisted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    The first time you look at a web page and its source code, you are probably a little intimidated by the use of symbols and jargon that really looks foreign to you. You might not even know where to start to begin learning what it all means. That’…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now