View: 1967|Reply: 8
|
Masalah untuk import javax.servlet.http.*
[Copy link]
|
|
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 |
|
|
|
|
|
|
|
dah buat environment dia? |
|
|
|
|
|
|
|
Ko pakai JDK ngan JRE brape? |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
cuba check file servelet tu ada tak? |
|
|
|
|
|
|
|
Reply #6 reza's post
servlet.jar yang kat dalam lib tu ke??
kalau yang tu memang ada dalam folder lib tu |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
| |
|