简体   繁体   English

Spring MVC和Apache Tiles:404问题

[英]Spring MVC and Apache Tiles: an 404 issue

Good Time. 美好时光。

I'm trying to integrate the Spring MVC and Apache Tiles. 我正在尝试整合Spring MVC和Apache Tiles。 The problem is^ when I hit the url I need, the "404 Not Found" raises. 问题是^当我点击所需的网址时,出现“ 404 Not Found”。 Here are my settings: 这是我的设置:

web.xml web.xml

<web-app id="WebApp_ID" version="2.4"
     xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Administration Panel</display-name>

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

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

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

</web-app>

tiles.xml Tiles.xml

<tiles-definitions>
<definition name="layout" template="/WEB-INF/jsp/templates/layout.jsp">
    <put-attribute name="title" value=""/>
    <put-attribute name="header" value="layout.header"/>
    <put-attribute name="navigator" value="layout.navigator"/>
    <put-attribute name="body" value=""/>
    <put-attribute name="footer" value="layout.footer"/>
</definition>

<!-- The header template -->
<definition name="layout.header" template="/WEB-INF/jsp/templates/header.jsp">
    <put-attribute name="header.left" value="/WEB-INF/jsp/themes/basic/header/layout_header_left.jsp"/>
    <put-attribute name="header.center" value="/WEB-INF/jsp/themes/basic/header/layout_header_center.jsp"/>
    <put-attribute name="header.right" value="/WEB-INF/jsp/themes/basic/header/layout_header_right.jsp"/>
</definition>

<!-- The navigator template -->
<definition name="layout.navigator" template="/WEB-INF/jsp/templates/navigator.jsp">
    <put-attribute name="navigator.top" value="/WEB-INF/jsp/themes/basic/navigator/layout_navigator_top.jsp"/>
    <put-attribute name="navigator.bottom" value="/WEB-INF/jsp/themes/basic/navigator/layout_navigator_bottom.jsp"/>
</definition>

<!-- The footer template -->
<definition name="layout.footer" template="/WEB-INF/jsp/templates/footer.jsp">
    <put-attribute name="footer.left" value="/WEB-INF/jsp/themes/basic/footer/layout_footer_left.jsp"/>
    <put-attribute name="footer.center" value="/WEB-INF/jsp/themes/basic/footer/layout_footer_center.jsp"/>
    <put-attribute name="footer.right" value="/WEB-INF/jsp/themes/basic/footer/layout_footer_right.jsp"/>
</definition>
<definition name="blank" extends="layout">
    <put-attribute name="body" value="/WEB-INF/jsp/themes/basic/body/layout_body.jsp"/>
</definition>

</tiles-definitions>

mvc-dispatcher-servlet.xml mvc-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:lang="http://www.springframework.org/schema/lang"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">


<context:component-scan base-package="xxx.xxx" />
<context:annotation-config/>

<mvc:annotation-driven />

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles.xml</value>
        </list>
    </property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>

</beans>

controller 控制者

@Controller
@RequestMapping("/base_page")

public class BasePageController {

@RequestMapping("/blank")
public ModelAndView getBasePage(HttpServletRequest request, HttpServletResponse response) {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("blank");
    return  modelAndView;
}

  }

The requested url is: http://localhost:8080/base_page/blank (tomcat 7) 要求的网址是: http://localhost:8080/base_page/blank (tomcat 7)

Can anybody suggest the solution? 有人可以建议解决方案吗?

Thanks Xaerxess and axtavt! 谢谢Xaerxess和axtavt!

The problem is solved, as axtavt pointed, by changing /* to /admin/* . 正如axtavt指出的,通过将/*更改为/admin/*可以解决该问题。

Now the question is why Spring is looking for the applicationContext.xml when the xxx-servlet.xml is already here? 现在的问题是,当xxx-servlet.xml已经存在时,为什么Spring正在寻找applicationContext.xml? And what type of beans are required to be placed in the applicationContext.xml (not in other spring configuration files)? 以及哪种类型的bean需要放置在applicationContext.xml中(而不是其他spring配置文件中)?

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

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