[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem in Form (This is a small mini project)

Posted on 2006-04-20
7
Medium Priority
?
171 Views
Last Modified: 2010-04-01
package minopharm;
// This is an order form
import java.io.IOException;
import java.io.PrintWriter;
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 {
            doPost(request,response);
      }        
            
      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+"'");
                  resultset.next();
                  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("<center>");
                  out.println("<table border=1>");
                  out.println("<tr>");
                  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>");*/
out.println("</tr>");
                  j=1;
while(resultset.next())  //  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
{
      productName=resultset.getString(1);
      out.println("<tr>");
      out.println("<td>"+j+"</td>");
out.println("<td width=150><input type=checkbox name=cb value='"+productName+"'>");
out.println(productName+"</td>");
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>");
      j++;
                  }
                  out.println("</table><br>");
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) {
                  e.printStackTrace();
            }
            
      }                    
}
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
0
Comment
Question by:divvela2001
5 Comments
 

Author Comment

by:divvela2001
ID: 16504907
PLZ give reply to me
0
 
LVL 16

Accepted Solution

by:
suprapto45 earned 128 total points
ID: 16505081
Hi,

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.

David
0
 
LVL 11

Assisted Solution

by:fargo
fargo earned 124 total points
ID: 16505765
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)
0
 
LVL 8

Assisted Solution

by:colr__
colr__ earned 124 total points
ID: 16505833
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.

colr__
0
 
LVL 19

Assisted Solution

by:actonwang
actonwang earned 124 total points
ID: 16506258
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

Acton
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

If anyone asked you to network diagram of the internet, it was drawn in the form of a fluffy cloud which further became known as cloud computing. Popularly cloud computing is defined as workloads that run over the internet in a commercial provider’s…
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 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