【问题标题】:How to publish java web project in tomcat如何在tomcat中发布java web项目
【发布时间】:2015-05-28 11:45:41
【问题描述】:

为了在tomcat中发布一个java-web应用程序,我将名为'demo-mvc'的项目复制到tomcat的webapps文件夹中。然后我在启动tomcat后在chorme浏览器中访问“http://localhost:8080/demo-mvc/xx.jsp”,但它提示“The请求的资源不可用”。我尝试按如下方式编辑 server.xml

<Context docBase="D:\apache-tomcat-7.0.57\webapps\demo-mvc" path="/demo-mvc" reloadable="true" source="org.eclipse.jst.jee.server:website"/>

最后还是没有效果。我很困惑问题出在哪里。

【问题讨论】:

  • 应用程序是否在 Tomcat 中无法启动,即您是否在日志中获得任何堆栈跟踪?
  • 复制后你重启服务器了吗?
  • 我已经重启了服务器
  • 你能得到tomcat自带的web应用示例吗?您是否还添加了身份验证以访问默认 tomcat 安装中的各个页面?

标签: java spring-mvc tomcat


【解决方案1】:

尝试从 Project clean 选项中清理您的项目,并确保您正在映射所有资源

在您的 web.xml 中,代码应该是这样的:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

【讨论】: