i'm not quite sure this is the right forum to post this... please forgive me...

i'm making a servlet
it takes info from an html form and uploads it to a data base using jdbc
that works just fine

each time i run it, i get a console report that i want to view into a new html web page but two errors appear

this are my headers

import java.io.*;
import java.sql.*;
import java.text.*;
//import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

this is part of the code

public void doGet(HttpServletRequest req,
                   HttpServletResponse res)
                   throws ServletException, IOException {
  out = res.getWriter();

  try {
  } catch (Exception e) {
   System.err.println( "error!" );
  Date d = new Date();
  SimpleDateFormat f = new SimpleDateFormat("EEEE, MMMM d, yyyy");
  String ds = f.format(d);
  SimpleDateFormat f1 = new SimpleDateFormat("hh:mm a");
  String ts = f1.format(d);
  Date dout = new Date(d.getTime()+1000*60*45);
  String ts1 = f1.format(dout);
  out.println("<TD>Date: "+ds+"<BR/>Time: "+ts+"</TD></TR>");

//stuff, stuff, stuff

the errors are

cannot find symbol
symbol: method SendFile(java.lang.String);
//that is the file i want to put the report in...

cannot find symbol
symbol: constructor Date();

that is sql.Date
if i uncomment the
//import java.util.*;
it says its an ambiguos call

can anyone tell me what am i missing to use the SendFile() and how to fix Date()?

in the end i can get rid of displaying date, but i want the sendfile working. please help (or tell me in which thread should i post this to get an answer)

7 Years
Discussion Span
Last Post by javaAddict

forgot to add the sendfile code

void SendFile(String filename) throws IOException,FileNotFoundException  {
  BufferedReader f = new BufferedReader(new FileReader(filename));
  String line;
   while ((line=f.readLine())!=null) {

For all regular usage, you would want to use the Calendar and java.util.Date classes. java.sql.Date class is normally used in JDBC context. Read this. You get the error because java.sql.Date doesn't have a no-arg constructor.

BTW, which class has this 'SendFile' method of yours? Is it in a separate class or in the same servlet? If it's in the servlet, post the entire servlet class definition.

Edited by ~s.o.s~: n/a


There are 2 Date objects:
the java.util.Date and the java.sql.Date. The sql.Date doesn't have a Date() constructor. Only the util.Date has.

If you need both try:

java.util.Date d = new java.util.Date();
java.sql.Date dout = new java.sql.Date(.....);

check their APIs

Although your whole logic is not the best approach. Don't use servlet, for displaying. Forward an object to a jsp page through the request and do the rendering in that jsp page. Don't put html code in a servlet.

Search for some tutorials

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.