运行和部署servlet与eclipse和tomcat 7 [英] running and deploying servlet with eclipse and tomcat 7

查看:125
本文介绍了运行和部署servlet与eclipse和tomcat 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我创建了一个基于使用Eclipse的Tomcat HelloWorld Servlet

  2. ,并尝试从Eclipse中运行它,因为Tomcat 7已配置为在127.0.0.1上运行,但是我得到页面找不到在127.0.0.1/helloworld/HelloWorld

  3. 我也尝试导出为war文件并将其部署到(否则工作)Tomcat服务器作为Windows服务运行,并与Tomcat Application Manager - manifest.mf一起部署,这些类很好地复制到tomcat / webapps / helloworld,但是尝试导航到127.0.0.1/helloworld/HelloWorld再次失败,显示 HTTP状态404

  1. I created a test project based on Tomcat HelloWorld Servlet with Eclipse
  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
  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



从默认的@WebServlet到web.xml配置



接下来,在HelloWorld.java中,我尝试注释

From default @WebServlet to web.xml configuration

Next, in HelloWorld.java, I tried commenting out

//@WebServlet("/HelloWorld")

和t添加一个web应用程序特定的web.xml配置:

and then adding a web-application-specific web.xml configuration:

<?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!


  • 给定链接教程提供了Tomcat 6的说明,我应该更改某些内容以使其与Tomcat 7配合使用?

  • 具体来说,Eclipse添加的默认值为$ code> @WebServlet(/ HelloWorld) Servlet 3.0的注释配置需要什么(不需要web.xml)?

  • 或者是阻止在全局tomcat服务器级别的任何Web应用程序部署?我已经改变了服务器配置有点,不幸的是我不记得什么,除了使它服务于127.0.0.1而不是127.0.0.1:8080

  • Given the linked tutorial provides instructions for Tomcat 6, should I change something to make it work with Tomcat 7?
  • Specifically, is the default @WebServlet("/HelloWorld") added by Eclipse sufficient? What is needed for the annotation-based configuration of Servlet 3.0 to work (without web.xml)?
  • Or could it be that something is blocking any web app deployment at the global tomcat server level? 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

推荐答案

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

Open the properties page of your dynamic web project, click on "web project settings" and use the context root paramter as the root path for your URL.

这篇关于运行和部署servlet与eclipse和tomcat 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆