Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Programming Error
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Harshu
Programming Error
3 Answer(s)      4 years and 11 months ago
Posted in : JSP-Servlet


<%@ 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.

Advertisement
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


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  Hello Sir, how to convert a txt written in textarea of html must get converted to integers and should get displayed... integer.parseInt but its giving error. Please Reply me . Thank you
Programming Error - JSP-Servlet
Programming Error   Place Ad function funct(){ if(document.form.DraftAd.value=="" || document.form.DraftAd.value==null... ??? And when i tried its giving me error than cannot find variable.In
Programming Error - JSP-Servlet
Programming Error  Hello Sir, import java.util.*; import...(); } } }//End of class m geeting error in this can u please tell me whats the error nd how to solve
Programming error - JDBC
Programming error  import javax.servlet.*; import...) { out.println("Database Error :"+se.getMessage()); } catch(Exception e) { out.println(e.toString()); } } } Please reply me the error in this program because i
Programming Error - JSP-Servlet
Programming Error   Place Order function checkName...(""); } catch(SQLException se) { out.println("Database Error :"+se.getMessage()); } catch(Exception e) { out.println("General Error :"+e.getMessage
Programming error - JSP-Servlet
Programming error  Register.jsp Registration..."); } catch(SQLException se) { out.println("Database Error :"+se.getMessage()); } catch(Exception e) { out.println("General Error :"+e.getMessage()); } %>
Programming error - JSP-Servlet
Programming error  Actually there is an error in placeorder.jsp file where there are 5 fields OrderNo ,Name , Address, Email, PhoneNo where if I delete an order of client based on orderno then suppose in database if there are 5
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 - Java Beginners
programming error  What is error in this page and how to use RequestDispatcher in servlet to validate it please do reply?? import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; import
programming error - Java Beginners
programming error  import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class Place_Ad extends...) { out.println("Database Error :"+se.getMessage()); } catch(Exception e
programming error - Java Beginners
programming error  how can we statically implement linked list????????  Hi Friend, Please visit the following links: http://www.roseindia.net/java/jdk6/LinkedListExample.shtml http://www.roseindia.net/java
Programming Error - JSP-Servlet
Programming Error  Image: I want that when user clicks on browse button then a folder of images should get open and when user clicks one image from it (only one not more than that)then it should get displayed on next page
Programming error - JSP-Servlet
Programming error  Hello Sir, Can u please reply me the code for javamail please actually i watch the javamail.net but i dint understood it. Actually i want to send a mail to my clients with a small text message. Please
Programming Error - JSP-Servlet
Programming Error  Image: Browse When user clicks on Browse Button then a folder of images should get open and when user clicks one of them then the path of that should get saved in Access Database and on next page
Programming Error - JSP-Servlet
Programming Error   Payment Advertisement Management System Payment Premium Position FrontPage BackPage Other Premium Pages Page 2 Page 3 Page 5 Page 7 Total Cost: How to use switch
Programming Error - JSP-Servlet
Programming Error   Place Ad function funct(){ if(document.form.DraftAd.value=="" || document.form.DraftAd.value==null) { document.form.cnt.value=0;} else {document.form.cnt.value
Programming Error - JSP-Servlet
Programming Error  How to validate login page using jsp where it checks for username whether it is empty or not or is it including number or not if it is the paste alert message.   Hi Friend, Try the following
Programming Error - JSP-Servlet
Programming Error   function Draft() { if(document.form.Count.value==""||document.form.Count.value==null) document.form.Count.value=0; else document.form.Count.value = document.form.DraftAd.value.split(' ').length
Programming error - JSP-Servlet
Programming error   Payment Advertisement Management System Payment Premium Position FrontPage BackPage Other Premium Pages Page 2 Page 3 Page 5 Page 7 Total Cost: I want that the no of characters
Programming Error - JSP-Servlet
Programming Error  Ya States and cities and maincategory and subcategory are combobox and maincategory contains suppose matrimonial then sub category will contain groom and bride, if main category contains vehicals then sub
Programming Error - JSP-Servlet
Programming Error   Place Ad Advertisement Management System Create Ad State: City: Main Category: Sub Category: Title: Draft Your Ad Here
 

 

 

DMCA.com