0

我的应用程序在本地 tomcat 7 上运行良好,但在 prod tomcat 7 上只有索引 url(“/”)和资源 url 有效,其他 url 未找到,例如“/login”。

servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<annotation-driven />

<resources mapping="/resources/**" location="/resources/" />

<!-- FreeMarker Config -->
<beans:bean id="freemarkerConfig"
    class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <beans:property name="templateLoaderPath" value="/WEB-INF/views/" />
</beans:bean>

<!-- FreeMarker View Resolver -->
<beans:bean id="viewResolver"
    class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <beans:property name="cache" value="true" />
    <beans:property name="prefix" value="" />
    <beans:property name="suffix" value=".html" />
</beans:bean>

<context:component-scan base-package="com.x.y" />

</beans:beans>

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">

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

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

试图解决我将servlet-mapping从<url-pattern>/</url-pattern>to更改为<url-pattern>/*</url-pattern>但没有成功,但如果我输入后缀“.jsp”,它就会开始找到url,例如:/login.jsp。

谁能帮我理解为什么tomcat正在等待这个“.jsp”后缀?我什至没有在我的应用程序中使用 jsp:s

控制器示例:

@Controller
public class Application extends BaseController {

    //...

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model, HttpSession session) {
        //..
        return "application/index";
    }

        @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(Model model, HttpSession session) {
        //..
        return "application/login";
    }

    //...
}

谢谢。

4

1 回答 1

0

听起来您可能在生产环境中将 apache 放在 tomcat 前面,并且它只通过某些 url,例如:*.jsp 或者,它可能是阻止某些 URL 的防火墙。

于 2013-08-03T00:18:49.993 回答