Problem in Form (This is a small mini project)

package minopharm;
// This is an order form
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.PreparedStatement;

 public class CreateOrder1 extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
      private static final long serialVersionUID = 1L;
      String partyName;
      String productName;
      ResultSet resultset,resultset1;
      PreparedStatement pstmt;
      int j;
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            PrintWriter out=response.getWriter();
            partyName=request.getParameter("partyName");// here we are getting partyname from partyinformation page
            Date d =new Date();
            Connection connection=DBAccess.createODBCConnection();
            out.println("<head><title> Order Form </title>");
            out.println("<font face=arial >");
            out.println("<center><h1> ORDER FORM</h1></center>");
            try {
                  Statement statement=connection.createStatement();
                  resultset=statement.executeQuery("select partyCodeNo,drugLicenseNo20B,drugLicenseNo21B,vatNo,cstNo from party_Information where partyName='"+partyName+"'");
                  out.println("<form name=order method=post action=PartyOrder>");
                  out.println("<b>Customer Code : <input type=text name=customerCode value="+resultset.getString(1)+">");
                  out.println("Order Number : <input type=text name=orderNo value=ord"+j+">");
                  out.println("Date : <input type=text name=date  size=20 value="+d.getDate()+"/"+(d.getMonth()+1)+"/"+(d.getYear()+1900)+"><br>");
                  out.println("DrugLicence No 20B <input type=text name=drugLicenseNo20B value="+resultset.getString(2)+">");
out.println("21B<input type=text name=drugLicenseNo21B value="+resultset.getString(3)+">");
out.println("VAT/CST No : <input name=orderNo type=text  value="+resultset.getString(4)+"><br><br><br>");
                  resultset=statement.executeQuery("select ProductName,UnitOfPacking from product_Add order by productname");
                  ResultSetMetaData metadata=resultset.getMetaData();
                  out.println("<table border=1>");
                  out.println("<td width=50><center><b> S.NO </b></td>");
                  for(int i=1;i<=metadata.getColumnCount();i++)
out.println("<td width=130><center><b>"+metadata.getColumnName(i)+"</b></td>");
out.println("<td width=80><center><b> Q.ty </b></center></td>");
                  for(int i=1;i<=metadata.getColumnCount();i++)
out.println("<td width=130><center><b>"+metadata.getColumnName(i)+"</b></td>");
out.println("<td width=50><center><b> Q.ty </b></center></td>");*/
while(  //  We are getting all the product names from the product table and we //are giving checkbox option to the customer to select the product
// WE are displaying all the products in table format.Customer will select the products
out.println("<td width=150><input type=checkbox name=cb value='"+productName+"'>");
out.println("<td width=100><center>"+resultset.getString(2)+"</center></td>");
out.println("<td width=80><center><input type=text name='"+productName+"' size=3></center>");
out.println("<center><input type=button value=Generate >");// Generate button
out.println("<input type=text name=totalcost><br><br>");// Total Cost will be displayed in this text box upon clicking Generate button
out.println("<input type=submit value=CreateOrder>&nbsp;&nbsp;&nbsp;");
out.println("<input type=reset value=Cancel>");
            } catch (SQLException e) {
Upon clicking GENERATE Button(which is a Button ,not a SUBMIT Button), we need to get the products and Quantity Ordered by the Customer (which is in that Page only) and NetPrice of selected products  that has to be Obtained from PriceList table(database) and we have to display the total amount in this page only .
  How to solve this problem
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

divvela2001Author Commented:
PLZ give reply to me

Why can't you make it a submit button then? If you intend to still use the normal button, you may need to either pass it from Session or as GET variables.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
it's not a good idea to use servlet for such handlings.
Instead use jsp and make a server round trip on clicking the generate button to get the net price. (u need to avoid the submission or insert/update on db with some parameter handling)
This can be done with Javascipt. On loading the page, youll need to make sure that you have 'Obtained from PriceList table(database) ' and make this avaiable to the javascipt code (use the JSP to dynamically write some javascript with the values you need in it).

When the user clicks the button, this will fire a javascript function that will collect the values entered by the user, perfrom the calculation and update the page with the result. This can all be done without leaving the page.

whichever you want :servlet or jsp, in your code, here:

out.println("<center><input type=button value=Generate >");// Generate button

you'd have to add a "onclick" event handler which will do some thing on this page as:

out.println("<center><input type=button value=Generate onclick='<your js function>'>");// Generate button

then you'd put the js function there.

Yup, I'd suggest you switch to jsp instead of servlet ESPECIALLY in your case.
depending on your case, your js function either:
1. submit the form and return back another page
2. use AJAX (if extra information needed) or javascript function to generate result

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.