jsp page

jsp page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language="javascript">
function validate()
{

var productName=document.addp.productName.value;
var desc=document.addp.desc.value;
var features=document.addp.features.value;
var price=document.addp.price.value;
var quantity=document.addp.quantity.value;
var thresholdLimit=document.addp.thresholdLimit.value;


if(productName==null||productName=="")
{
    alert("product name must be filled out");
    return false;
}
if(desc==null||desc=="")
{
    alert("description must be filled out");
    return false;
}
if(features==null||features=="")
{
    alert("features must be filled out");
    return false;
}
if(quantity==null||quantity=="")
{
    alert("quantity must be filled out");
    return false;
}
else if(isNaN(quantity))
{
    alert("quantity should be a number");
    return false;
}
if(price==null||price=="")
{
    alert("price must be filled out");
    return false;
}
else if(isNaN(price))
{
    alert("Price should be a number");
    return false;
}
if(thresholdLimit==null||thresholdLimit=="")
{
    alert("threshold limit must be filled out");
    return false;
}

else if(isNaN(thresholdLimit))
{
    alert("Threshold limit should be a number");
    return false;
}
}
</script>
</head>

<body>
<h2><center>TELECOM STORE INVENTORY</center></h2>

<title>Add Product</title>
<table>
    <tr>

    <td width="800"><p align ="center"></p></td>

    </tr>
</table>


<table align="center" border="3" cellpadding="7" cellspacing="2"  >

/*  <tr>
    <td width="220" align="center" bgcolor="#B0C4DE"><font size="5"  ><a href="main1.html">  Home  </a></font></td>
    <td width="220" align="center" bgcolor="#B0C4DE"><font size="5" color=""><a href="main2.html">  Product  </a></font></td>
    <td width="220" align="center" bgcolor="#B0C4DE"><font size="5" color=""><a href="main3.html" >  Stock  </a></font></td>
    <td width="220" align="center" bgcolor="#B0C4DE"><font size="5" color=""><a href="main4.html">  Sales Promotion  </a></font></td>

    </tr>*/
</table>
<h2><center>ADD PRODUCT MODEL</center></h2>
<form name="addp" method="post"  action="ProductServlet" onsubmit="return validate();">

    <table  align="center" cellpadding="10" cellspacing="10" >

  <tr>
    <td>Product Model Name</td>
    <td><input type="text" name="productName"></td>
  </tr>
  <tr>
    <td>Description</td>
    <th><input type="text" name="desc"></th>
  </tr>
  <tr>
    <td>Features</td>
    <th><input type="text" name="features"></th>
  </tr>
  <tr>
    <td>Price</td>
    <th><input type="text" name="price"></th>
  </tr>
  <tr>
    <td>Quantity</td>
    <th><input type="text" name="quantity"></th>
  </tr>
  <tr>
    <td>Threshold Limit</td>
    <th><input type="text" name="thresholdLimit"></th>
  </tr>
  <tr>
    <td>Eligibility for Rewards</td>
    <th><select name="eligibility"><option>Yes</option><option>No</option></select></th>
  </tr>
  <tr><td><center>
  <input type="submit"  id="button" value="Add" name="addproduct"/></center></td>

      <td><center><input type="Reset" value="Reset"/></center></td>
  </tr>
</table> 


</form>
</body>
</html>
View Answers

April 24, 2012 at 11:08 AM

The code works fine. It seems that you forget to specify your query. Anyways, if you want to insert data into database then we are providing you an example. Here it is:

1)form.html:

<html>
<form method="post" action="http://localhost:8080/examples/jsp/insert.jsp">
<table>
<tr><td>First Name:</td><td><input type="text" name="fname"></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="lname"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Confirm Password:</td><td><input type="password" name="cpass"></td></tr>
<tr><td>Date Of Birth</td><td><input type="text" name="dob"></td></tr>
<tr><td>Age:</td><td><input type="text" name="age"></td></tr>
<tr><td>Gender</td><td><input type="text" name="gender"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address"></td></tr>
<tr><td>Country</td><td><input type="text" name="country"></td></tr>
<tr><td>State:</td><td><input type="text" name="state"></td></tr>
<tr><td>City</td><td><input type="text" name="city"></td></tr>
<tr><td>Telephone No:</td><td><input type="text" name="tno"></td></tr>
<tr><td>Mobile:</td><td><input type="text" name="mobile"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)insert.jsp:

<%@page import="java.sql.*,java.util.*"%>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
String pass=request.getParameter("pass");
String cpass=request.getParameter("cpass");
String dob=request.getParameter("dob");
int age=Integer.parseInt(request.getParameter("age"));
String gender=request.getParameter("gender");
String address=request.getParameter("address");
String country=request.getParameter("country");
String state=request.getParameter("state");
String city=request.getParameter("city");
int telephone=Integer.parseInt(request.getParameter("tno"));
int mobile=Integer.parseInt(request.getParameter("mobile"));
        try{
         Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
           Statement st=con.createStatement();
           int i=st.executeUpdate("insert into student(firstname,lastname,email,pass,confirm_pass,dob,age,gender,address,country,state,city,telephone,mobile) values('"+fname+"','"+lname+"','"+email+"','"+pass+"','"+cpass+"','"+dob+"',"+age+",'"+gender+"','"+address+"','"+country+"','"+state+"','"+city+"',"+telephone+","+mobile+")");
        out.println("Data is successfully inserted!");
        }
        catch(Exception e){
        System.out.print(e);
        e.printStackTrace();
        }
        %>

Ads









Related Tutorials/Questions & Answers:
jsp page
jsp page  <%@page contentType="text/html" pageEncoding="UTF-8"%>...;%@page import="java.sql.Statement"%> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.Connection"%> <%@page import
JSP Tutorials - Page 3
JSP Tutorials - Page 3
Advertisements
jsp page
jsp page  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Easily create JSP page
Easily create JSP page  Hi, How I can easily create JSP page? Where to run the JSP page easily? Thanks   Hi, JSP stands for Java Server Pages and its easy to create a simple JSP page. Check the tutorial: How
jsp page submitting
jsp page submitting  whenever i am submitting the jsp page it downloads some unknown file on tomcat server
create a folder in jsp page
create a folder in jsp page  i want to create a folder in jsp page And it can be delete aslo
JSP Hindi Page - JSP-Servlet
JSP Hindi Page  I need to provide users with option to print a Certificate in English or Hindi. This is an html page generated by JSP Code. Depending upon the button clicked english or hindi version of the Certificate should
The Page Directive in JSP Page
The Page Directive in JSP Page     ... of the JSP page which works for the entire JSP page. These directives apply different... and explanation one-by-one. This is the directive of the JSP page which defines
Unable to execute JSP page
folder. But I could not execute the JSP page. Please help me...Unable to execute JSP page  I have written one jsp file. It contains html tags and jsp directives. I have saved the file with the extension .jsp
Search Page in jsp
Search Page in jsp  search page in jsp   Please go through the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
jsp login page
jsp login page  hi tell me how to create a login page using jsp and servlet and not using bean... please tell how to create a database in sql server... please tell with code
Search page form in jsp
Search page form in jsp  search form in jsp   Please go through the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
list to be displayed in jsp page.
list to be displayed in jsp page.  Can any one help me? Am developing the code in struts.I have a list in action class that has to be printed in the dropdownlist in another jsp page.Please help me in the code.. Thank u
jsp page authentication panel using jsp/servlet?
jsp page authentication panel using jsp/servlet?  I have 10 jsp jsp forms and 7 users and i want to grant variour permission like edit,delete and save for users dynamically on forms.So please refer me code
JSP LOGIN Page
JSP LOGIN Page  sir....i have two user types usercategory and user and both user have userid and password in two different table and now i am making login page for which i have to retrieve usertype,userid and password from two
download or save jsp page
download or save jsp page  hii.., this is my jsp page .. This page is theater ticket. i want to download this page. so i need to save this page...="text/html" pageEncoding="UTF-8"%> JSP Page
download or save jsp page
download or save jsp page  hii.., this is my jsp page .. This page is theater ticket. i want to download this page. so i need to save this page...="text/html" pageEncoding="UTF-8"%> JSP Page
Hide the Jsp Page
Hide the Jsp Page  I want to hide the Entire JSP Page.is it possible
Search operation in JSP page
Search operation in JSP page  How to perform search in jsp with MYSQL database plz help me
Forward a Jsp Page
Forward a Jsp Page In this example program we will show you how to use the <... is not logged in you can forward the user on the login page. Here is the use of <jsp:forward tag: <jsp:forward page="
how to create web page on jsp?
how to create web page on jsp?  how to create web page on jsp
jsp reload current page problem
jsp reload current page problem  Hi, i am facing problem while reloading the JSP page
jsp reload current page problem
jsp reload current page problem  Hi, i am facing problem while reloading the JSP page
How to make first JSP page?
How to make first JSP page?  Hello, How I can make first JSP page? Thanks
Switch case in Jsp page
using switch case in jsp page...Switch case in Jsp page  <table> <tr><td>Enter Distance :</td> <td><input type="text" name="dis"/></td>
JSP Error Page
JSP Error Page          JSP Error Page is used to specify the custom... of errorPage attribute of the page directive in jsp. This attribute sets a url
How To Include Two Jsp page in another jsp page?
How To Include Two Jsp page in another jsp page?  I use following code to Include Two Jsp Page Header and footer <%@include file="header.jsp... in page How can i Display at correct position?   Please visit
.xhtml or .jsp page in a jsf project
.xhtml or .jsp page in a jsf project  in a jsf project which pages should i use, .jsp or .xhtml? and why ? what are adventages or dis adventages jsp and xhtml pages. thanks
jsp page to Showuser details
jsp page to Showuser details   SHOWUSERS.JSP: <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@taglib uri="/WEB-INF/struts..." prefix="logic" %> <%@page contentType="text/html" pageEncoding="UTF-8"%>
embed ganttChart on JSP page
embed ganttChart on JSP page   How I can embed ganttChart on JSP page ??? Im already created ganttChart by using this example: To create a simple Gantt chart, try the following code: import java.awt.Color; import
JSP Page Error
JSP Page Error  Hello Sir. I m using Oracle 10g as a database n... i run jsp page on the browser it only shows the code nothing else.. I have...;/html> 2) insert.jsp <%@ page import="package oracle.jdbc.driver;" %>

Ads