Programming Error

Programming Error

<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.lang.String.*" %>
<%
Connection con=null;
//ResultSet state=null;
Statement stmt=null;
String st;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Advdsn");
stmt=con.createStatement();

}
catch(SQLException se)
{
out.println("Database Error:"+se.getMessage());
}
catch(Exception e)
{
e.toString();
}

%>
<HTML>
<HEAD>
<TITLE> Place Ad </TITLE>

<script language="text/JavaScript" >

function func()
{
var filename = document.form.img.value;
window.location.href=("http://localhost:8080/ProjectAd/Preview?

filename="+filename);
}
function Draft(){

if(document.form.DraftAd.value=="" || document.form.DraftAd.value==null)
{
document.form.cnt.value=0;}
else
{document.form.cnt.value = document.form.DraftAd.value.split(' ').length;}
}
</script>



</HEAD>

<BODY BGCOLOR="lightblue">
<marquee behavior="alternate" scrollamount=5 scrolldelay=10><h1><font size=4 face="Stroustroup" color="#993355">Advertisement Management System</h1></font></marquee><br>
<p align=center><b> <font color="669933" size=4>Create Ad </font></b></p><br>
<form name="form" action="http://locathost:8080/ProjectAd/Preview" method=post>
State: <select name="State" size=1>
<%
ResultSet state=stmt.executeQuery("Select * from PlaceAd where State is not null ");

while(state.next())
{
%>
<option>
<%
out.println(state.getString("State"));
%>
</option>
<%}%>
</select><br>

City: <select name="City" size=1>
<%
ResultSet city=stmt.executeQuery("Select * from PlaceAd where City is not null");
while(city.next())
{
%>
<option>
<%

out.println(city.getString("City")); %>
</option>
<%}%>
</select><br>
Main Category: <select name="mainCat" size=1>
<%
ResultSet mainC=stmt.executeQuery("Select * from PlaceAd where MainCategory is not null");
while(mainC.next())
{
%>
<option>
<%

out.println(mainC.getString("MainCategory")); %>
</option>
<%}%>
</select><br>
Sub Category:<select name="subCat" size=1>
<%
ResultSet subC=stmt.executeQuery("Select * from PlaceAd where SubCategory is not null");
while(subC.next())
{
%>
<option>
<%

out.println(subC.getString("SubCategory")); %>
</option>
<%}%>
</select><br>
Title: <input type=text name="Title" size=25 onkeyup="return Validate();"><br>

<p>Draft Your Ad Here:<textarea name="DraftAd" cols="15" rows="2" onkeyup="Draft();"></textarea>
<br>
<input name="cnt" type="text" value="" readonly>

<p>Image:<input type="file" name="img">
<!--<input type="button" name="c" value="Save">--></p>

Email:<input type=text name="Email" size=25><br>
Phone No:<input type=text name="PhoneNo" size=25><br>
Select Newspaper:<select name="NewsPaper" size=1>
<%
ResultSet newspaper=stmt.executeQuery("Select * from PlaceAd where NewsPaper is not null");
while(newspaper.next())
{
%>
<option>

<%

out.println(newspaper.getString("NewsPaper")); %>
</option>
<%}%>
</select><br>
Select Your Date:<select name="Date" size=1>

<%for (int date=1;date<=31;date++)
{
%>
<br><option>

<%out.println(date);
%>
</option>
<%}%>
</select>
Month:<select name="Month" size=1>
<%
for (int month=1;month<=12;month++)

{
%>
<option>
<%

out.println(month);
%>
</option>
<%}%>
</select>
Year:<select name="Year" size=1>
<%
for (int year=1960;year<=2010;year++)
{
%>
<option>
<%
out.println(year);
%>
</option>
<%}%>
</select><br>
Select Number of Days:<input type=text name="Days" size=5><br>
<!--<p>Confirm:<input type=checkbox name=confirm ></p>-->
<input type="button" name="c" value="Save" >
<br>
<p><input type=button name=submit value=Submit onClick="func();"><br>

</form>
</BODY>
</HTML>

Code for Preview:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class Preview extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
//HttpSession hs=req.getSession(true);
//String count=req.getParameter("cnt");
//hs.putValue("Count",count);

//File file=new File(f);
//FileInputStream in=new FileInputStream(file);

out.println("<html><body bgcolor=lightblue>");
out.println("<font align=center size=5 color=Green>Preview</font><br>");
out.println("</body></html>");

String title=req.getParameter("Title");
out.println(title+"<br>");
String f=req.getParameter("filename");
out.println(f+"<br>");
String st=req.getParameter("State");
out.println("<p align=center>"+st+"<br>");
String ct=req.getParameter("City");
out.println(ct+"<br>");
String mc=req.getParameter("mainCat");
out.println(mc+"<br>");
String sc=req.getParameter("subCat");
out.println(sc+"<br>");
String da=req.getParameter("DraftAd");
out.println(da+"<br>");
String count=req.getParameter("cnt");
out.println(count+"<br>");
String np=req.getParameter("NewsPaper");
out.println(np+"<br>");
String dt=req.getParameter("Date");
out.println(dt+"-");
String mth=req.getParameter("Month");
out.println(mth+"-");
String y=req.getParameter("Year");
out.println(y+"<br>");
String days=req.getParameter("Days");
out.println(days+"<br>");
out.println("<a href=\"http://localhost:8080/ProjectAd/Payment.jsp\">Payment</a>");
}
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{doPost(req,res);}
}

I want that state,city,maincategory subcategory,title,draftad,count,image,etc should get displayed on next page and it should get inserted oin database.
Please Reply me Sir How to do it??
Please Sir ThankYou Sir.
View Answers

February 5, 2010 at 1:30 PM

Hi Friend,

Try the following code:

1)placead.jsp:

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>

<html>
<head>
<script language="JavaScript">
function func(){

var filename = document.form.img.value;
var st=document.form.State.value;
var ci=document.form.City.value;
var main=document.form.mainCat.value;
var sub=document.form.subCat.value;
var title=document.form.Title.value;
var ad=document.form.text1.value;
var cnt=document.form.text2.value;
var email=document.form.Email.value;
var pno=document.form.PhoneNo.value;
var np=document.form.NewsPaper.value;
var date=document.form.date.value;
var mon=document.form.Month.value;
var year=document.form.Year.value;
var day=document.form.Days.value;
window.open("http://localhost:8080/examples/Preview?filename="+filename+"&st="+st+"&ci="+ci+"&main="+main+"&sub="+sub+"&title="+title+"&ad="+ad+"&cnt="+cnt+"&email="+email+"&pno="+pno+"&np="+np+"&date="+date+"&mon="+mon+"&year="+year+"&day="+day);
}
function Draft(){
document.form.text2.value = document.form.text1.value.split(' ').length;
}
function insert(){

var filename = document.form.img.value;
var st=document.form.State.value;
var ci=document.form.City.value;
var main=document.form.mainCat.value;
var sub=document.form.subCat.value;
var title=document.form.Title.value;
var ad=document.form.text1.value;
var cnt=document.form.text2.value;
var email=document.form.Email.value;
var pno=document.form.PhoneNo.value;
var np=document.form.NewsPaper.value;
var dt=document.form.date.value;
var mon=document.form.Month.value;
var year=document.form.Year.value;
var day=document.form.Days.value;
window.open("http://localhost:8080/examples/jsp/save.jsp?filename="+filename+"&st="+st+"&ci="+ci+"&main="+main+"&sub="+sub+"&title="+title+"&ad="+ad+"&cnt="+cnt+"&email="+email+"&pno="+pno+"&np="+np+"&dt="+dt+"&mon="+mon+"&year="+year+"&day="+day);
}
</script>
</head>

<body bgcolor="lightblue">
<marquee behavior="alternate" scrollamount=5 scrolldelay=10><h1><font size=4 face="Stroustroup" color="#993355">Advertisement Management System</h1></font></marquee><br>
<p align=center><b> <font color="669933" size=4>Create Ad </font></b></p><br>

February 5, 2010 at 1:31 PM

continue..

<form name="form" >
<table>
<tr><td>State:</td><td> <select name="State" size=1>
<option value="Maharashtra">Maharashtra</option>
<option value="UttarPradesh">UttarPradesh</option>
</select></td></tr>
<tr><td>City:</td><td> <select name="City" size=1>
<option value="Mumbai">Mumbai</option>
<option value="Pune">Pune</option>
<option value="Bareilly">Bareilly</option>
<option value="Lucknow">Lucknow</option>
</select></td></tr>
<tr><td>Main Category: </td><td><select name="mainCat" size=1>
<option value="A">A</option>
<option value="B">B</option>
</select></td></tr>

<tr><td>Sub Category:</td><td><select name="subCat" size=1>
<option value="A1">A1</option>
<option value="A2">A2</option>
<option value="B1">B1</option>
<option value="B2">B2</option>
</select></td></tr>
<tr><td>Title:</td><td> <input type=text name="Title" size=25 ></td></tr>
<tr><td>Draft Your Ad here:</td><td><textarea name="text1" cols="15" rows="2" onkeyup="Draft();"></textarea></td></tr>
<tr><td>No of words:</td><td><input name="text2" type="text" value="" ></td></tr>
<tr><td>Image:</td><td><input type="file" name="img"></td></tr>
<tr><td>Email:</td><td><input type=text name="Email" size=25></td></tr>
<tr><td>Phone No:</td><td><input type=text name="PhoneNo" size=25></td></tr>
<tr><td>Select Newspaper:</td><td><select name="NewsPaper" size=1>
<option value="Times of India">Times of India</option>
<option value="Hindustan Times">Hindustan Times</option>
</select></td></tr>
<br>
<tr><td>Select Your Date:</td><td><select name="date" size=1>

<%for (int date=1;date<=31;date++)
{
%>
<option value="<%=date%>"><%=date%></option>
<%}%>
</select></td></tr>
<tr><td>Month:</td><td><select name="Month" size=1>
<%
for (int month=1;month<=12;month++){
%>
<option value="<%=month%>"><%=month%></option>
<%}%>
</select></td></tr>
<tr><td>Year:</td><td><select name="Year" size=1>
<%
for (int year=1960;year<=2010;year++){
%>
<option value="<%=year%>"><%=year%></option>
<%}%>
</select></td></tr>
<tr><td>Select Number of Days:</td><td><input type=text name="Days" size=5></td></tr>
<tr><td><input type="button" name="c" value="Save" onclick="insert();"></td><td><input type=button name=submit value=Submit onclick="func();"></td></tr>
</form>
</body>
</html>

February 5, 2010 at 1:32 PM

continue..

2) save.jsp:

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
String st=request.getParameter("st");
String ct=request.getParameter("ci");
String main=request.getParameter("main");
String sub=request.getParameter("sub");
String title=request.getParameter("title");
String da=request.getParameter("ad");
String count=request.getParameter("cnt");
String f=request.getParameter("filename");
String email=request.getParameter("email");
String pno=request.getParameter("pno");
String np=request.getParameter("np");
String dt=request.getParameter("dt");
String mth=request.getParameter("mon");
String y=request.getParameter("year");
String days=request.getParameter("day");
File file=new File(f);
FileInputStream in=new FileInputStream(file);
System.out.println(dt+" "+mth+" "+y);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement ps = con.prepareStatement("INSERT INTO PlaceAd(State,City,MainCategory,SubCategory,Title,DraftAd,Count,Image,Email,PhoneNo,Newspaper,day,Month,Year,Days) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
ps.setString(1,st);
ps.setString(2,ct);
ps.setString(3,main);
ps.setString(4,sub);
ps.setString(5,title);
ps.setString(6,da);
ps.setInt(7,Integer.parseInt(count));
ps.setBinaryStream(8,in,(int)file.length());
ps.setString(9,email);
ps.setInt(10,Integer.parseInt(pno));
ps.setString(11,np);
ps.setInt(12,Integer.parseInt(dt));
ps.setInt(13,Integer.parseInt(mth));
ps.setInt(14,Integer.parseInt(y));
ps.setInt(15,Integer.parseInt(days));
ps.execute();
ps.close();
out.println("Data is saved successfully");
%>

3)Preview.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class Preview extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body bgcolor=lightblue>");
out.println("<font align=center size=5 color=Green>Preview</font><br>");
String st=req.getParameter("st");
out.println(st+"<br>");
String ct=req.getParameter("ci");
out.println(ct+"<br>");
String mc=req.getParameter("main");
out.println(mc+"<br>");
String sc=req.getParameter("sub");
out.println(sc+"<br>");
String title=req.getParameter("title");
out.println(title+"<br>");
String da=req.getParameter("ad");
out.println(da+"<br>");
String count=req.getParameter("cnt");
out.println(count+"<br>");
String f=req.getParameter("filename");
out.println("<img src='"+f+"' height='40' width='40'/><br>");
String email=req.getParameter("email");
out.println(email+"<br>");
String pno=req.getParameter("pno");
out.println(pno+"<br>");
String np=req.getParameter("np");
out.println(np+"<br>");
String dt=req.getParameter("date");
out.println(dt+"-");
String mth=req.getParameter("mon");
out.println(mth+"-");
String y=req.getParameter("year");
out.println(y+"<br>");
String days=req.getParameter("day");
out.println(days+"<br>");
out.println("<a href=\"http://localhost:8080/ProjectAd/Payment.jsp\">Payment</a>";);
out.println("</body></html>");

}
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{doPost(req,res);}
}
Thanks

Ads









Related Tutorials/Questions & Answers:
programming error
programming error  I got an error when i did the following program the prg. is to "select the name from database when the age is given for the respective name" error i got is:SQL exception please give me the solution by providing
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
Advertisements
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  <p>import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*;</p> <p>public class Login extends HttpServlet { public void doPost(HttpServletRequest
Programming error - JSP-Servlet
Programming error   --%> Place Order function Validate() { var valid=true; if(document.forms.OrderNo.value=="") { alert... where if @ is not given or (dot). is not given etc then it should display error
Programming Error - JSP-Servlet
Programming Error  import java.util.*; import javax.mail.*; import javax.mail.internet.*; public class SendMail { public static void main(String args[]) throws Exception { String host = "192.168.10.205
Programming Error - JSP-Servlet
Programming Error   Place Ad function func() { var filename = document.form.img.value; window.location.href=("http://localhost:8080/ProjectAd/Preview? filename="+filename); } function Draft
Programming
Programming  Given a number n, write a programming to determine its square root if it is possible, in the contraly case print an appropriate massege on the screen
programming
Java Constructor programming for single and double constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
Error-
Error-   Hello, I would like to know about XSD file. I try to print XML file but I am getting error SAXException-- says Content is not allowed in prolog. Please help me
error
error  i have 404 error in my program plz tell me yhe solution about
error
error  i have 404 error in my program plz tell me yhe solution about
error
/ServletUserEnquiryForm.shtml getting an error given below SQLException caught: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error please suggest
Error
Error  I have created ajax with php for state and city. When I change state then city will not come in dropdown list and it give me error as 'Unknown Runtime Error'. This error come only in IE browser, but in other brower
error
error
error
error  When I deploye the example I have this message cannot Deploy HelloWorld Deployment Error for module: HelloWorld: Error occurred during deployment: Exception while deploying the app [HelloWorld
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern = /^\d{3,5
error
error  whats the error.............. import java.util.Scanner; public class g { public static void main(String[] args) { Scanner s=new Scanner(System.in); int d,x,y; System.out.println("Enter the first number
network programming
network programming   Tutorial for Network programming and administration

Ads