JAVA servlet import 报错

蓝湛江 2011-10-22 02:18:58
import java.io.IOException;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.List;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import com.itcast.manager.BookManager;

import com.itcast.web.entity.Book;


public class ServletBook extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

doPost(request, response);

}


public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String type = request.getParameter("type");

if (type != null && type.trim().equalsIgnoreCase("findById")) {


} else if (type != null && type.trim().equalsIgnoreCase("findAll")) {


} else if (type != null && type.trim().equalsIgnoreCase("deleteById")) {


} else if (type != null && type.trim().equalsIgnoreCase("deleteAll")) {


} else {

List<Book> bs = new ArrayList<Book>();

BookManager bm = BookManager.getInstance();

bs = bm.findAll();

request.getSession().setAttribute("bs", bs);

response.sendRedirect("/day10/listBook.jsp");

}


}

}





很简单的类 居然第8行 import报错





An error occurred at line: 8 in the generated java file

Syntax error on token "import", Identifier expected after this token


Stacktrace:] with root cause



试过把所有注释掉 只写一个重定向也不行 求解..
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Paradise_heida 2011-10-22
  • 打赏
  • 举报
回复
风尘中国 2011-10-22
  • 打赏
  • 举报
回复
你工程里面没有加入servlet-api.jar 所以无法找到servlet这个包

你需要下载或者到tomcat的lib目录下找到这个 jar包,然后加入到你工程的classpath当中

工程名-右键-buildpath-configuration-add jars 或者add external jars 加入到工程应该就没有这个问题了

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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