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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Harshu
Programming
0 Answer(s)      4 years and 9 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>

I want that all this value should get displayed on next page as preview along with selected image
and when i click on save it should get save in access database and when i click on submit it should get displayed on next page and in script the Draft () function is not working and there is some problem in this code.

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);}
}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
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
Advertisements
Programming with JSP
Programming with JSP  Who will post me the answer
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
Ajax programming
Ajax programming  Hi, How I can start ajax programming easily? I... concept. What should be my starting point for Ajax programming? Thanks   Hi, If you have prior programming experience in any web development
Programming with JSP
Programming with JSP  Write a program using jsp that accepts a course code as input and displays the course title the program to which it belongs
Programming (general)
Programming (general)  I haven't yet started college/university but I'm interested in studying programming. I wondering if programming is difficult or confusing with all the codes you have to learn? Also how many languages would
programming concept
programming concept  Write a program that allows the user to input a total dollar amount for an online shopping order and computes and outputs the shipping cost based on the following schedule
programming of foxpro
programming of foxpro  hello sir , sir i am use the foxpro . but i know about c . sir how can i learn fox pro . i know about something about foxpro
C Programming
C Programming  hi,how can i write a program in C programming to place reservation in air plane from the menu let the user to inter his/her gender(W or M)and draw seats by using ascii codes and choose where he/she will sit
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
Socket Programming
Socket Programming  How to connect a computer through IP only and check whether it is up and running? I can't see any method in Socket programming where I can pass only IP address as argument. I need the pass port number also
programming c#
programming c#   create and make use of at least one class with appropriate instance methods to solve the programming problem. use console-based menus to navigate between the functionality offered by the application. at least one
Programming Assignment
Programming Assignment  Hey there, We were given an assignment to write a program to read 10 student marks from the keyboard without using an Array (only using switch statements, if statements or loops). As each mark is input
 

 

 

DMCA.com