当前位置: 技术问答>java相关
一个简单的Servlet的问题
来源: 互联网 发布时间:2017-03-09
本文导语: 源代码如下: import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /**Hello World! Servlet Class */ public class HelloWorld extends HttpServlet { /**doGet方法的重载,用于处理客户端的GET请求*/ public void doGet(HttpServletRequest...
源代码如下:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**Hello World! Servlet Class */
public class HelloWorld extends HttpServlet
{
/**doGet方法的重载,用于处理客户端的GET请求*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("");
out.println("Hello World!");
out.println("");
out.println("");
out.println("Hello World!");
out.println("");
out.println("");
}
}
------------------------------
编译时的错误信息如下:
HelloWorld.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
HelloWorld.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloWorld.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class HelloWorld
public class HelloWorld extends HttpServlet
^
HelloWorld.java:9: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloWorld
public void doGet(HttpServletRequest request, HttpServletResponse respon
se)
^
HelloWorld.java:9: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloWorld
public void doGet(HttpServletRequest request, HttpServletResponse respon
se)
^
HelloWorld.java:10: cannot resolve symbol
symbol : class ServletException
location: class HelloWorld
throws IOException, ServletException
^
6 errors
------------------------------
我的JDK环境配置是不是有问题呢?
一般的java文件编译都是正常的。是不是Servlet的运行还需要什么特殊的组件呢?
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**Hello World! Servlet Class */
public class HelloWorld extends HttpServlet
{
/**doGet方法的重载,用于处理客户端的GET请求*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("");
out.println("Hello World!");
out.println("");
out.println("");
out.println("Hello World!");
out.println("");
out.println("");
}
}
------------------------------
编译时的错误信息如下:
HelloWorld.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
HelloWorld.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloWorld.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class HelloWorld
public class HelloWorld extends HttpServlet
^
HelloWorld.java:9: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloWorld
public void doGet(HttpServletRequest request, HttpServletResponse respon
se)
^
HelloWorld.java:9: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloWorld
public void doGet(HttpServletRequest request, HttpServletResponse respon
se)
^
HelloWorld.java:10: cannot resolve symbol
symbol : class ServletException
location: class HelloWorld
throws IOException, ServletException
^
6 errors
------------------------------
我的JDK环境配置是不是有问题呢?
一般的java文件编译都是正常的。是不是Servlet的运行还需要什么特殊的组件呢?
|
你的机器上要么没有servlet.jar要么不在系统路径下,你先查找一下servlet.jar文件在不在?若不在,请安装tomcat4.1,若在,请检查一下系统路径有没有指向这个文件。
|
没找到servlet包,你是在哪里编译的?
|
如果有Jbuilder或者tomcat等,或者下载一个servlet.jar文件,并且将该文件加入到classpath中。
|
你应该是用jdk直接编译的吧,你应该找个servlet的包加到你个classpath里去,装了tomcat的话,去里面找有这个包的。
|
classpath裡沒有servlet.jar
tomcatcommonlib下有.
tomcatcommonlib下有.