在Spring Web应用程序中的web.xml中配置url-pattern

时间:2014-03-24 23:18:41

标签: spring spring-mvc

在我的Spring应用程序中,我有以下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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>HorarioLivre2</display-name>

  <welcome-file-list>
    <welcome-file>acesso/login.html</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>HorarioLivre2</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>HorarioLivre2</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>
</web-app>

我的问题是:尽管采用这种方式正确找到页面,如果我将网址格式更改为&#39; /&#39;,我无法访问任何网页(登录网页 - 我项目中的第一个)。我甚至为welcome-file尝试了几种组合,比如acesso / login,acesso / login /,/ acesso / login,/ acesso / login / etc.)。

我的spring-servlet.xml文件是:

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

        <context:component-scan base-package="com.horariolivre"/>
            <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
                <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
                <property name="prefix" value="/WEB-INF/jsp/" />
                <property name="suffix" value=".jsp" />
            </bean>

        <context:annotation-config>
            <bean class="com.horariolivre.resources.HibernateConfig">
            </bean>
        </context:annotation-config>

        <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

我的控制器之一是:

@Controller
@RequestMapping(value="acesso")
public class PrimaryController {

    @Autowired
    private SessaoHome sessao;

    @Autowired
    private UsuarioHome usuario;

    @RequestMapping(value="login")
    public ModelAndView login() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("acesso/login");
        return mav;
    }
    (...)
}

有人知道我应该用于网址格式的正确路径&#39; /&#39;?

1 个答案:

答案 0 :(得分:0)

您可以将您的网址格式设为*/*