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
1 Answer(s)      4 years and 9 months ago
Posted in : JSP-Servlet


Place.jsp

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%@page import="java.lang.String.*" %>
<%
Connection con=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>
<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.DraftAd.value;
var cnt=document.form.Count.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.location.href=("http://localhost:8080/ProjectAd/Preview.jsp?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.Count.value = document.form.DraftAd.value.split(' ').length;
}
function checkPhoneNo(num){
if(isNaN(num)){alert("Invalid Phone Number. The only characters permitted are 0 to 9"); return 0;}
else{return 1;}
}
function Validate()
{
var phone=document.form.PhoneNo;
var email=document.form.Email;
if(email.value=="")
{ alert("Please enter valid Email Id");
return false;
}
apos=email.value.indexOf("@")
dotpos=email.value.lastIndexOf(".")
if (apos<1 || dotpos-apos<2)
{
alert("Invalid Email Id")
email.value=="";
email.focus();
return false;
}

if((phone.value=="")||(phone.value==null))
{ alert("Please enter valid PhoneNo");phone.focus();
return false;
}
if (checkPhoneNo(phone.value)==false){
phone.value="";
phone.focus();
return false;
}
if ((phone.value.length==8)||(phone.value.length==10)){
return true;
}
else{
alert("Phone Number must be of 8 numbers or 10 numbers");
return false;
}
return true;
}
</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" onsubmit="return Validate();">
<table>
<tr><td>State:</td><td> <select name="State" size=1>
<%
ResultSet state=stmt.executeQuery("SELECT distinct DomainValue FROM Domain WHERE DomainName = 'StateCd' Order by 1 ");
while(state.next())
{
%>
<option>
<%
out.println(state.getString("DomainValue"));
%>
</option>
<%}%>s
</select></td></tr>
<tr><td>City:</td><td> <select name="City" size=1>
<%
ResultSet city=stmt.executeQuery("Select DepDomainValue from Domain where DomainName='StateCd' Order by 1");
while(city.next())
{
%>
<option>
<%

out.println(city.getString("DepDomainValue")); %>
</option>
<%}%>
</select></td></tr>

<tr><td>Main Category: </td><td><select name="mainCat" size=1>
<%
ResultSet mainC=stmt.executeQuery("SELECT distinct DomainValue FROM Domain WHERE domainname = 'Category' Order by 1");
while(mainC.next())
{
%>
<option>
<%

out.println(mainC.getString("DomainValue")); %>
</option>
<%}%>
</select></td></tr>

<tr><td>Sub Category:</td><td><select name="subCat" size=1>
<%
ResultSet subC=stmt.executeQuery("Select DepDomainValue from Domain where DomainName='Category' Order by 1");
while(subC.next())
{
%>
<option>
<%

out.println(subC.getString("DepDomainValue")); %>
</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="DraftAd" cols="15" rows="2" onkeyup="Draft();"></textarea></td></tr>
<tr><td>No of words:</td><td><input name="Count" 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 maxlength=10></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=2010;year<=2050;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=submit value=Preview onClick="func();"></td></tr>
</form>
</body>
</html>

Preview.jsp

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


<HTML>
<HEAD>
<TITLE> Preview </TITLE>
<script language="JavaScript">

function insert(){

window.location.href=("http://localhost:8080/ProjectAd/save.jsp");
}
</script>
</HEAD>

<BODY BGCOLOR="lightblue">
<p align=center><font size=5 color=Green>Preview</font></p><br>
<%
String title=request.getParameter("title");
String f=request.getParameter("filename");
String dt=request.getParameter("date");
String np=request.getParameter("np");
String mth=request.getParameter("mon");
String y=request.getParameter("year");
String days=request.getParameter("day");
String da=request.getParameter("ad");
String count=request.getParameter("cnt");
String st=request.getParameter("st");
String ct=request.getParameter("ci");
String mc=request.getParameter("main");
String sc=request.getParameter("sub");
String email=request.getParameter("email");
String pno=request.getParameter("pno");

out.println("<p align=left>Title:"+title+"</p>");
out.println("<img align=left src='"+f+"' height=150 width=150 /></img><br>");
out.println(np+"<br>");
out.println("Date:"+dt+"-");
out.println(mth+"-");
out.println(y+"<br>");
out.println("No.of.Days:"+days+"<br>");
out.println("<p align=center>Text:"+da+"<br>");
out.println("Words: "+count+"<br>");
out.println("State:"+st+"<br>");
out.println("City:"+ct+"<br>");
out.println("MainCategory:"+mc+"<br>");
out.println("SubCategory:"+sc+"<br>");
out.println("Email:"+email+"<br>");
out.println("PhoneNo:"+pno+"<br>");

%>
<hr color=green>
<p align=center>
<form name="form" onsubmit="http://localhost:8080/ProjectAd/save.jsp"><input type="submit" name="submit" value="Save" ></form>


</BODY>
</HTML>

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("date");
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:Advdsn");
PreparedStatement ps = con.prepareStatement("INSERT INTO Image(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.setString(10,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));
int x=ps.executeUpdate();
if(x>0)
out.println("Data is saved successfully");
else
response.sendRedirect("place.jsp");
ps.close();
%>

<a href="http://localhost:8080/ProjectAd/Payment.jsp">Payment</a>

Payment.jsp<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.lang.String.*" %>

<%@ page session = "true" %>
<%
String c=(String)session.getAttribute("Count");
int c1=Integer.parseInt(c);
//out.println(c1*500);
float b=(float)(c1*500)/15;
//out.println(b);
//if(request.getParameter("FP")!=null)
//{
//Float fp=457200+b;
//out.println(fp);
//}
//else
//{out.println("Select something");}
%>

<HTML>
<HEAD>
<TITLE> Payment </TITLE>
<script type="text/javascript">
function check(){
if(document.form.FP.value!=null)
{
var fp=457200+b;
alert("price="+fp);
}
else
{document.write("Select something");}
}
</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>
<h2 align=center><font color="#663366">Payment</font></h2>
<p><b><font color="#336633">Premium Position</font></b></p><br>
<form method=post name=form>
<input type=radio name=FP>FrontPage<input type=button name=check onclick="check.jsp" value="Send"><br>
<!--<input type=radio name=BP id=Edi>BackPage<br>-->
<p><b><font color="#336633">Other Premium Pages</font></b></p><br>
<!--<input type=radio name=P2 id=Edi>Page 2<br>
<input type=radio name=P3 id=Edi>Page 3<br>
<input type=radio name=P5 id=Edi>Page 5<br>
<input type=radio name=P7 id=Edi>Page 7<br><br>-->
</form>
Total Cost:<input type=text name=Total size=5 >
</BODY>
</HTML>

In this file place.jsp i want that when user types say 3 days and 8-2-10
in date,month,year then in preview page it should add the days to the current date and give the enddate and the startdate from current date.

in preview page output is coming tht i can preview everything but when i click on save button its not getting saved in database can you let me know the problem please.

there is some error in this page canu tell me whats the problem.

Please check the Save page there some error in it??
Please do reply me ??
Thank you sir..

Advertisement
View Answers

February 8, 2010 at 4:16 PM


Hi Friend,

In order to display Start and End date, do changes in your Preview.jsp.

Preview.jsp:

<%@page language="java" import="java.io.* ,java.sql.*,java.util.*,java.text.*"%>


<HTML>
<HEAD>
<TITLE> Preview </TITLE>
</HEAD>

<BODY BGCOLOR="lightblue">
<p align=center><font size=5 color=Green>Preview</font></p><br>
<%
String title=request.getParameter("Title");
String f=request.getParameter("img");
String dt=request.getParameter("day");
String np=request.getParameter("NewsPaper");
String mth=request.getParameter("Month");
String y=request.getParameter("Year");
String ndays=request.getParameter("numDays");
String da=request.getParameter("DraftAd");
String count=request.getParameter("Count");
String st=request.getParameter("State");
String ct=request.getParameter("City");
String mc=request.getParameter("mainCat");
String sc=request.getParameter("subCat");
String email=request.getParameter("Email");
String pno=request.getParameter("PhoneNo");

out.println("<p align=left>Title:"+title+"</p>");
out.println("<img align=left src='"+f+"' height=150 width=150 /></img><br>");
out.println(np+"<br>");
out.println("Start Date: "+dt+"-"+mth+"-"+y+"<br>");
String DATE_FORMAT = "dd-MM-yyyy";
SimpleDateFormat sdf =new java.text.SimpleDateFormat(DATE_FORMAT);
Calendar c1 = Calendar.getInstance();
c1.set(Integer.parseInt(y),Integer.parseInt( mth)-1 ,Integer.parseInt( dt));
c1.add(Calendar.DATE,Integer.parseInt(ndays));
System.out.println( sdf.format(c1.getTime()));
out.println("End Date: "+sdf.format(c1.getTime()));
out.println("<p align=center>Text:"+da+"<br>");
out.println("Words: "+count+"<br>");
out.println("State:"+st+"<br>");
out.println("City:"+ct+"<br>");
out.println("MainCategory:"+mc+"<br>");
out.println("SubCategory:"+sc+"<br>");
out.println("Email:"+email+"<br>");
out.println("PhoneNo:"+pno+"<br>");
%>
<hr color=green>
<p align=center>
<form name="form" action="saves.jsp">
<input type="submit" name="submit" value="Save" >
<input type="hidden" name="st" value="<%=st%>">
<input type="hidden" name="ci" value="<%=ct%>">
<input type="hidden" name="main" value="<%=mc%>">
<input type="hidden" name="sub" value="<%=sc%>">
<input type="hidden" name="title" value="<%=title%>">
<input type="hidden" name="ad" value="<%=da%>">
<input type="hidden" name="cnt" value="<%=count%>">
<input type="hidden" name="filename" value="<%=f%>">
<input type="hidden" name="email" value="<%=email%>">
<input type="hidden" name="pno" value="<%=pno%>">
<input type="hidden" name="np" value="<%=np%>">
<input type="hidden" name="day" value="<%=dt%>">
<input type="hidden" name="mon" value="<%=mth%>">
<input type="hidden" name="year" value="<%=y%>">
<input type="hidden" name="days" value="<%=ndays%>">
</form>
</BODY>
</HTML>

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
Advertisements
 

 

 

DMCA.com