新手:用Myeclipse 10第一次创建servlet 里面的package提示错误

qq_35741906 2016-08-29 11:38:46
tomcat 7x 都配置部署好了,上http://localhost:8080/TestTomCat也能看到内容了。





package com.Tjxz.zzx;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FirstServlet extends HttpServlet {

/**
* Constructor of the object.
*/
public FirstServlet() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}


servlet.api的包也导入了,自己学实在太费劲了,一步一出错,哪位前辈能帮忙看看怎么解决?
...全文
2560 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
syso_y 2018-01-15
  • 打赏
  • 举报
回复
求解决!!!!!
qq_35716530 2017-08-14
  • 打赏
  • 举报
回复
怎么解决的啊
summertimefly 2017-03-21
  • 打赏
  • 举报
回复
怎么解决的?
夜袭-牡丹花 2016-11-26
  • 打赏
  • 举报
回复
你好楼主,遇到和你同样的问题搞了两天了,快疯了,也是一枚自学党,1.8jdk匹配的应该是tomcat.8,切换到(MYeclipse自带)1.6JDK后,红叉去掉后但是编译当前目录下的index.JSP文件,会报异常,点击确定以后会跳转到另一个web项目下的,index.jsp页面,jsp文件没有异常,就是servlet不行,其他包都可以
qq_28141601 2016-10-08
  • 打赏
  • 举报
回复
以后建WEB工程总不能一直改jdk版本吧,我现在用的是jdk1.8
qq_26137681 2016-09-17
  • 打赏
  • 举报
回复
原来我的问题是自己的JDK版本过高
qq_26137681 2016-09-17
  • 打赏
  • 举报
回复
回复了才看到完整内容
qq_26137681 2016-09-17
  • 打赏
  • 举报
回复
请问怎么解决的啊?我的也出这个问题。
qq_35741906 2016-08-29
  • 打赏
  • 举报
回复


改成小写了,还是一样的错误提示
BUG胡汉三 2016-08-29
  • 打赏
  • 举报
回复
包名全部小写:com.tjxz.zzx
giya射手 2016-08-29
  • 打赏
  • 举报
回复
引用 4 楼 qq_35741906 的回复:
谢谢啊,解决了,怎么给分啊,是点击对我有用吗·?
结贴,给分。
qq_35741906 2016-08-29
  • 打赏
  • 举报
回复
谢谢啊,解决了,怎么给分啊,是点击对我有用吗·?
giya射手 2016-08-29
  • 打赏
  • 举报
回复
方法1.选择Eclipse的Window→Preferences→Java→Compiler,把Compiler compliance level从1.5改成1.6; 方法2.右击project选择最后一个properties选择左侧的java compiler,勾选里面的框框,把java编辑器版本都改成1.6; 方法3.右击project下的 JRE System Library[JavaSE-1.5]→Properties,Execution environment 选择“JavaSE-1.6(JDK1.6.0_10)”,点击确定即可。

81,091

社区成员

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

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