eclipse the import javax.servlet cannot be resolved ''''

---------------http://stackoverflow.com/questions/4076601/how-do-i-import-the-javax-servlet-api-in-my-eclipse-project

Ensure that you're using at least Eclipse IDE for Java EE developers (with the EE). It contains development tools to create dynamic web projects and easily integrate servletcontainers (which is part of Web Tools Platform, WTP). You also need to ensure that you already have a servletcontainer installed which implements at least the same Servlet API as the servletcontainer in the production environment, for example Apache TomcatOracle GlassfishJBoss AS, etc.

A servletcontainer is a concrete implementation of the Servlet API. Note that the Java EE SDK download at Oracle.com basically contains Glassfish. So if you happen to already have downloaded Java EE SDK, then you already have Glassfish. Also note that for example Glassfish and JBoss AS are more than just a servletcontainer, they also supports JSF, EJB, JPA and all other Java EE fanciness.

Once having installed both, do the following steps in Eclipse:

  1. Integrate servletcontainer in Eclipse. Open the Servers view in the bottom box, rightclick there and choose New > Server. Pick the appropriate servletcontainer make and version and walk through the wizard.

  2. Create new dynamic web project in Eclipse which is associated with the integrated servletcontainer. Open the Project Navigator on the left hand side. Rightclick there and choose New > Project and then in menu Web > Dynamic Web Project and set the Target Runtime to the integrated server. Eclipse will then automatically take the servletcontainer's libraries in the build path. This way you'll be able to import and use the Servlet API.

    Or if it's an existing project, you can set/change the server by Targeted Runtimes in project's properties.

You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries like servlet-api.jarjsp-api.jarel-api.jarj2ee.jarjavaee.jar, etc. It would only lead to future portability, compatibility, classpath and maintainability troubles, because your webapp would not work when it's deployed to a servletcontainer of a different make/version than where those libraries are originally obtained from.

Here are some typical exceptions which you can get when you litter the /WEB-INF/lib or even/JRE/lib/JRE/lib/ext, etc with servletcontainer-specific libraries:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值