简体   繁体   English

使用eclipse和tomcat 7运行和部署servlet

[英]running and deploying servlet with eclipse and tomcat 7

  1. I created a test project based on Tomcat HelloWorld Servlet with Eclipse 用Eclipse创建了一个基于Tomcat HelloWorld Servlet的测试项目
  2. and tried to run it from Eclipse as is with Tomcat 7, which I have configured to run on 127.0.0.1 - but I get Page cannot be found at 127.0.0.1/helloworld/HelloWorld 并尝试从Eclipse运行它,就像Tomcat 7一样,我已经配置为在127.0.0.1上运行 - 但我Page cannot be found在127.0.0.1/helloworld/HelloWorld
  3. I also tried exporting as war file and deploying it to the (otherwise working) Tomcat server running as a Windows service - and deployed with the Tomcat Application Manager - manifest.mf and the classes are nicely copied to tomcat/webapps/helloworld, but trying to navigate to 127.0.0.1/helloworld/HelloWorld fails again, showing HTTP Status 404 我还尝试导出为war文件并将其部署到作为Windows服务运行的(否则正常工作的)Tomcat服务器 - 并使用Tomcat应用程序管理器 - manifest.mf进行部署,并且这些类很好地复制到tomcat / webapps / helloworld,但是尝试导航到127.0.0.1/helloworld/HelloWorld再次失败,显示HTTP Status 404

From default @WebServlet to web.xml configuration 从默认的@WebServlet到web.xml配置

Next, in HelloWorld.java, I tried commenting out 接下来,在HelloWorld.java中,我尝试了注释

//@WebServlet("/HelloWorld")

and then adding a web-application-specific web.xml configuration: 然后添加特定于Web应用程序的web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <servlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorld</servlet-name>
        <url-pattern>/HelloWorld</url-pattern>
    </servlet-mapping>
</web-app>

But the results are still the same - no response! 但结果仍然相同 - 没有回应!

Solutions? 解决方案?

  • Given the linked tutorial provides instructions for Tomcat 6, should I change something to make it work with Tomcat 7? 鉴于链接教程提供了Tomcat 6的说明,我是否应该更改某些内容以使其与Tomcat 7一起使用?
  • Specifically, is the default @WebServlet("/HelloWorld") added by Eclipse sufficient? 具体来说,Eclipse添加的默认@WebServlet("/HelloWorld")足够? What is needed for the annotation-based configuration of Servlet 3.0 to work (without web.xml)? 基于注释的Servlet 3.0配置需要什么才能工作(没有web.xml)?
  • Or could it be that something is blocking any web app deployment at the global tomcat server level? 或者可能是某些东西阻止了全局tomcat服务器级别的任何Web应用程序部署? I have changed the server configuration somewhat, and unfortunately i do not remember exactly what, except for making it serve on 127.0.0.1 rather than 127.0.0.1:8080 我有点改变了服务器配置,不幸的是我不记得到底是什么,除了让它在127.0.0.1而不是127.0.0.1:8080上提供服务

打开动态Web项目的属性页面,单击“Web项目设置”,然后使用上下文根参数作为URL的根路径。

Try putting a default Index.html page in the WebContent and see if the welcome page points to it. 尝试在WebContent中放置一个默认的Index.html页面,看看欢迎页面是否指向它。 If yes then try entering the servlet name manually and see if that works. 如果是,则尝试手动输入servlet名称,看看是否有效。 I get the same error but doing so fixes it. 我得到了同样的错误,但这样做可以解决它。

http://localhost:8080/<Project_Name>/index.html

http://localhost:8080/<Project_Name>/servlet_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM