1

我有一个 Spring 项目,我可以使用 InternalResourceViewResolver 呈现普通视图。现在我正在尝试使用磁贴来模块化 UI。当我将浏览器指向http://localhost:8080/myapp/tradeaggregation时,我得到:

未找到带有 URI [/myapp/tradeaggregation] 的 HTTP 请求的映射。

网页.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-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-3.0.xsd
    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">

<annotation-driven />

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

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

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

<context:component-scan base-package="com.ks.kdweb.controllers" />

</beans:beans>

瓷砖.xml

<!DOCTYPE tiles-definitions PUBLIC 
    "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" 
    "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">

<tiles-definitions>
    <definition name="tradeaggregation" template="/WEB-INF/views/index.jsp">
        <put-attribute name="content" value="/WEB-INF/views/tradeAggregation.jsp"/>
    </definition>
</tiles-definitions>

我的控制器:

@Controller
public class TradeAggregatorController {
    private static final String TITLE = "Trade Aggregation";
    private static final String[] columns = new String[] { "listvalues", "numtrades", "sizesum" };

    @Autowired
    private JdbcAggConfigDefDao aggConfigDefDao;

    @RequestMapping("/tradeaggregation")
    public String load(@RequestParam("configdefid") long configDefId, @RequestParam("aggid") String aggId, Model model) {
        List<AggConfigDef> configs = this.aggConfigDefDao.getAggConfigDefsByType(TradeAggregation.class.getName());
        model.addAttribute("aggConfigs", configs);
        model.addAttribute("title", TITLE);
        model.addAttribute("tradeAggs", this.aggConfigDefDao.getTradeAggregations(configDefId, aggId));
        model.addAttribute("columns", columns);
        return "tradeaggregation";
    }

    public void setAggConfigDefDao(JdbcAggConfigDefDao aggConfigDefDao) {
        this.aggConfigDefDao = aggConfigDefDao;
    }
}
4

1 回答 1

0

在您的 web.xml 文件中尝试:

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
于 2012-08-30T21:47:54.800 回答