CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 1967|Reply: 8

Masalah untuk import javax.servlet.http.*

[Copy link]
Post time 28-8-2007 10:52 AM | Show all posts |Read mode
Aku ada buat coding untuk servlet ni tapi bila nak compile coding ni, dia ada error cakap

package javax.servlet does not exist
package javax.servlet.http does not exist
cannot find symbol
cannot find symbol class HttpServletRequest
cannot find symbol class HttpServletResponse
cannot find symbol class ServletException
cannot find symbol class UnavailableException
cannot find symbol class UnavailableException


ni coding aku

package beans;

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

public class BookingServlet extends HttpServlet
{
  private Connection connection;
  private Statement query;
      
  //setup database connection and prepare SQL statements
  public void init(ServletConfig config) throws ServletException
  {
    String driverClassName = config.getInitParameter("driverclassname");
    String dbURL = config.getInitParameter("dburl");

    //attempt database connection and create Statement
    try
    {
      //Load the driver class
      Class.forName(driverClassName);
      //get a database connection
      connection = DriverManager.getConnection(dbURL,"","");
      query = connection.createStatement();
    }
        
    //for any exception throw an UnavailableException to indicate that the servlet is not currently available
    catch (Exception exception)
    {
      exception.printStackTrace();
      throw new UnavailableException(exception.getMessage());
    }
  } //end of init method
   
  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
  {
    doPost(req, res);
  }

  //process booking
  protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
  {
    String userid = req.getParameter("userID");
    String dest = req.getParameter("destination");
    String dat = req.getParameter("date");
    String tim = req.getParameter("time");

    String sql = "INSERT INTO Booking VALUES ('"+userid+"','"+dest+"','"+dat+"','"+tim+"')";   

    try
    {
      query.executeUpdate(sql);

      //set userid in request to pass it on to bookingSuccess.jsp
      req.setAttribute("theName", userid);
                     
      //forward request to bookingSuccess.jsp
      req.getRequestDispatcher("/bookingSuccess.jsp").forward(req, res);
      return;
    }   
    catch (Exception exception)
    {
      exception.printStackTrace();
      throw new UnavailableException(exception.getMessage());        
    }
  }

  //close SQL statements and database when servlet terminates
  public void destroy()
  {
    //attemp to close statements and database connection
    try
    {
      query.close();
      connection.close();
    }
        
    //handle database exceptions by returning error to client
    catch(SQLException sqlException)
    {
      sqlException.printStackTrace();
    }
  } //end of destroy method
}         
                          
            
anyone?thanks
Reply

Use magic Report


ADVERTISEMENT


Post time 28-8-2007 10:59 AM | Show all posts
dah buat environment dia?
Reply

Use magic Report

Post time 28-8-2007 11:09 AM | Show all posts
Ko pakai JDK ngan JRE brape?
Reply

Use magic Report

 Author| Post time 28-8-2007 11:13 AM | Show all posts
untuk CLASSPATH aku refer ke

C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar

environtment aku dah setup ok dah termasuk JAVA_HOME,CATALINA_HOME
Reply

Use magic Report

 Author| Post time 28-8-2007 11:14 AM | Show all posts

Reply #3 Leybra's post

Aku pakai

j2sdk1.4.2_08
Reply

Use magic Report

Post time 28-8-2007 11:59 AM | Show all posts
cuba check file servelet tu ada tak?
Reply

Use magic Report

Follow Us
 Author| Post time 28-8-2007 01:03 PM | Show all posts

Reply #6 reza's post

servlet.jar yang kat dalam lib tu ke??
kalau yang tu memang ada dalam folder lib tu
Reply

Use magic Report

Post time 28-8-2007 05:06 PM | Show all posts
erm ....ko ada install application java lain kut? yg tgh kacau. Slalunya "does not exist" kiranya komputer cari tak jumpa ler

ko cuba guna netbean... pastu ko klik kat file tu ....dia redirect ke mana
Reply

Use magic Report


ADVERTISEMENT


Post time 28-8-2007 05:28 PM | Show all posts
your class path tu jangan lock kat satu folder aje,

Cuba tukar your classpath settings to this:

CLASSPATH = .;C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar

(notice ada tanda noktah and semicolon di depan CLASSPATH path tu)

try and see if it works. and, kalau dah set classpath, kena reboot PC dulu sebelum run semula for best results (although sometimes once dah tukar classpath dah OK dah)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

3-1-2025 03:08 AM GMT+8 , Processed in 0.151725 second(s), 21 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list