我有一个Spring项目,我可以使用InternalResourceViewResolver渲染普通视图。现在我正在尝试使用tile来模块化UI。当我将浏览器指向 http:// localhost:8080 / myapp / tradeaggregation 时,我得到:
找不到带有URI [/ myapp / tradeaggregation]的HTTP请求的映射。
的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的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>
tiles.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;
}
}
答案 0 :(得分:0)
在你的web.xml文件里面试试:
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>