.java编译后显示错误信息package javax.servlet does not exist该这么解决

mindynasty 2004-09-13 09:49:31
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FormGetExample extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
resonse.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<body bgcolor=\"white\">");
out.println("<head>");
out.println("<title>Servlet Get Example</title>");
out.println("</head>");
out.println("<body>");
out.println("<p> </p>");
out.println("<p><font size='+4'>"+"Servlet Get Example"+"</font></p>");
Enumeration enum= request.getParameterNames();
while(enum.hasMoreElements())
{
String key=(String)enum.nextElements();
String value=request.getParameter(key);
out.println("<p>");
out.println(key+"="+value);
out.println("</p>");
}
out.println("</body>");
out.println("</html>");
out.close();
}
}
这么一段代码编译后会出现这种错误
--------------------Configuration: j2sdk1.4.2_02 <Default>--------------------
C:\tomcat\webapps\myapp\WEB-INF\Servlets\FormGetExample.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
C:\tomcat\webapps\myapp\WEB-INF\Servlets\FormGetExample.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
C:\tomcat\webapps\myapp\WEB-INF\Servlets\FormGetExample.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class FormGetExample
public class FormGetExample extends HttpServlet{
^
C:\tomcat\webapps\myapp\WEB-INF\Servlets\FormGetExample.java:6: cannot resolve symbol
symbol : class HttpServletRequest
location: class FormGetExample
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
^
C:\tomcat\webapps\myapp\WEB-INF\Servlets\FormGetExample.java:6: cannot resolve symbol
symbol : class HttpServletResponse
location: class FormGetExample
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
^
C:\tomcat\webapps\myapp\WEB-INF\Servlets\FormGetExample.java:6: cannot resolve symbol
symbol : class ServletException
location: class FormGetExample
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
^
C:\tomcat\webapps\myapp\WEB-INF\Servlets\FormGetExample.java:7: cannot resolve symbol
symbol : variable resonse
location: class FormGetExample
resonse.setContentType("text/html");
^
C:\tomcat\webapps\myapp\WEB-INF\Servlets\FormGetExample.java:20: cannot resolve symbol
symbol : method nextElements ()
location: interface java.util.Enumeration
String key=(String)enum.nextElements();
^
8 errors

Process completed.

环境变量都设置好了
我是初学者不知道如何解决,请高人指点.先谢了!
...全文
757 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wybin 2004-09-14
  • 打赏
  • 举报
回复
同意wandou999(弯豆)说的。
drugon 2004-09-14
  • 打赏
  • 举报
回复
上面的几位己经讲清楚了!
wandou999 2004-09-14
  • 打赏
  • 举报
回复
将SERVLET.JAR 加入CLASSPATH
lxg2000 2004-09-14
  • 打赏
  • 举报
回复
把含有javax.servlet.*;的那个jar文件拷贝到
你键好的那个目录下的lib文件夹里
myapp\WEB-INF\lib
如果没有新建一个
mindynasty 2004-09-14
  • 打赏
  • 举报
回复
谢谢!

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧