我創建了一個java servlet程序名稱FirstServlet。編譯java servlet程序時出錯
我把它放在Tomcat的7.0 \的webapps \ ROOT \ WEB-INF \類\ FirstServlet.java,也是我設置類路徑的servlet-api.jar文件,但是當我編譯它
我發現一些錯誤。
代碼是:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
// Runs when the servlet is loaded onto the server.
public void init() {
//......
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Set the MIME type for the response message
response.setContentType("text/html");
// Write to network
PrintWriter out = response.getWriter();
// Your servlet's logic here
out.println("<html>");
out.println(" ...... ");
out.println("</html>");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// do the same thing as HTTP GET request
doGet(request, response);
}
public void destroy() {
// ......
}
}
錯誤是:
_並且我還設置了servlet-api.jar_的類路徑,不,您不知道。你運行了'javac FirstServlet.java' –
有什麼特別的原因沒有使用IDE?在那裏你可能會得到缺少的庫錯誤,並根據需要組織你的庫。 – porfiriopartida