当前位置: 技术问答>java相关
servlet为什么不能运行呢,请指教。
来源: 互联网 发布时间:2015-10-30
本文导语: 我已经装好了jdk和tomcat,运行java程序和jsp都好好的,但是我要编译一个servlet, 就老出错,如下面这个例程 import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorldExa...
我已经装好了jdk和tomcat,运行java程序和jsp都好好的,但是我要编译一个servlet,
就老出错,如下面这个例程
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldExample extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
String title = rb.getString("helloworld.title");
out.println("" + title + "");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("" + title + "");
out.println("");
out.println("");
}
}
老是出错,
HelloWorldExample.java:8: package javax.servlet doe
import javax.servlet.*;
^
HelloWorldExample.java:9: package javax.servlet.htt
import javax.servlet.http.*;
^
HelloWorldExample.java:17: cannot resolve symbol
symbol : class HttpServlet
location: class HelloWorldExample
public class HelloWorldExample extends HttpServlet
^
HelloWorldExample.java:20: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloWorldExample
public void doGet(HttpServletRequest request,
^
HelloWorldExample.java:21: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloWorldExample
HttpServletResponse response)
^
HelloWorldExample.java:22: cannot resolve symbol
symbol : class ServletException
location: class HelloWorldExample
throws IOException, ServletException
^
6 errors
是不是还要把tomcat下面一个什么.jar文件加到classpath中去呀,
是加那个呀,请大侠指教,多谢。
就老出错,如下面这个例程
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldExample extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
String title = rb.getString("helloworld.title");
out.println("" + title + "");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("" + title + "");
out.println("");
out.println("");
}
}
老是出错,
HelloWorldExample.java:8: package javax.servlet doe
import javax.servlet.*;
^
HelloWorldExample.java:9: package javax.servlet.htt
import javax.servlet.http.*;
^
HelloWorldExample.java:17: cannot resolve symbol
symbol : class HttpServlet
location: class HelloWorldExample
public class HelloWorldExample extends HttpServlet
^
HelloWorldExample.java:20: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloWorldExample
public void doGet(HttpServletRequest request,
^
HelloWorldExample.java:21: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloWorldExample
HttpServletResponse response)
^
HelloWorldExample.java:22: cannot resolve symbol
symbol : class ServletException
location: class HelloWorldExample
throws IOException, ServletException
^
6 errors
是不是还要把tomcat下面一个什么.jar文件加到classpath中去呀,
是加那个呀,请大侠指教,多谢。
|
add Tomcat 4.1commonlibservlet.jar to your classpath