当我的web.xml<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>里的url-pattern写成'/'.然后controller里的@RequestMapping("/"),这样写是可以正常访问到页面的如果我把xml里的'/'改成‘*.do’,@RequestMapping("/")改成@RequestMapping("test.do")就访问不到我的test.ftl了。这是什么情况我的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"> <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>test.ftl</welcome-file>
</welcome-file-list>
</web-app>
我的appServlet-servlet.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"> <context:component-scan base-package="com.fonsview.mymvc" />
<context:annotation-config /> <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven /> <beans:bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- 配置freeer模板 -->
<beans:bean class="org.springframework.web.servlet.view.freeer.FreeMarkerViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".ftl" />
<beans:property name="contentType" value="text/html;charset=UTF-8"></beans:property>
<beans:property name="requestContextAttribute" value="request" />
<beans:property name="exposeSpringMacroHelpers" value="true" />
<beans:property name="exposeRequestAttributes" value="true" />
<beans:property name="exposeSessionAttributes" value="true" />
</beans:bean>
</beans:beans>我的controller@RequestMapping("/")
public String test(Locale locale, Model model) {
List<People>peopleList=new ArrayList<People>();
People people=new People();
people.setName("coco");
people.setPosition("C52");
people.setSex("male");
People people2=new People();
people2.setName("linn");
people2.setPosition("C53");
people2.setSex("male");
peopleList.add(people);
peopleList.add(people2);
model.addAttribute("people", people);
model.addAttribute("peopleList", peopleList);
return "test";
}
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>里的url-pattern写成'/'.然后controller里的@RequestMapping("/"),这样写是可以正常访问到页面的如果我把xml里的'/'改成‘*.do’,@RequestMapping("/")改成@RequestMapping("test.do")就访问不到我的test.ftl了。这是什么情况我的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"> <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>test.ftl</welcome-file>
</welcome-file-list>
</web-app>
我的appServlet-servlet.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"> <context:component-scan base-package="com.fonsview.mymvc" />
<context:annotation-config /> <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven /> <beans:bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- 配置freeer模板 -->
<beans:bean class="org.springframework.web.servlet.view.freeer.FreeMarkerViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".ftl" />
<beans:property name="contentType" value="text/html;charset=UTF-8"></beans:property>
<beans:property name="requestContextAttribute" value="request" />
<beans:property name="exposeSpringMacroHelpers" value="true" />
<beans:property name="exposeRequestAttributes" value="true" />
<beans:property name="exposeSessionAttributes" value="true" />
</beans:bean>
</beans:beans>我的controller@RequestMapping("/")
public String test(Locale locale, Model model) {
List<People>peopleList=new ArrayList<People>();
People people=new People();
people.setName("coco");
people.setPosition("C52");
people.setSex("male");
People people2=new People();
people2.setName("linn");
people2.setPosition("C53");
people2.setSex("male");
peopleList.add(people);
peopleList.add(people2);
model.addAttribute("people", people);
model.addAttribute("peopleList", peopleList);
return "test";
}
解决方案 »
- 如何获取多条记录的值?
- 写一段时间段控制代码, 2007-08-29 至 2007-09-04 跳过接下来的程序执行.
- 这段代码可以在Linux下发邮件吗?(我在windows下没有任何问题.)
- 请教struts标签的问题。谢谢!
- 几个概念性的问题,不过比较重要,帮顶者也有分
- 关于连接池的使用!
- hibernate连接mysql时自动编号问题??请大家帮忙!!
- 急问难题关于postgre数据库
- 300分求可视化的设计器工具解决方法
- 用springMVC框架我要从A的数据回调给B的远程接口
- Hibernate初始化配置的问题
- The type Map is not generic; it cannot be parameterized with arguments
@RequestMapping("/")
public String test(Locale locale, Model model) {
改为:
@RequestMapping("/test.do")
public String test(Locale locale, Model model) {
@RequestMapping("/")
public String test(Locale locale, Model model) {
改为:
@RequestMapping("/test")
public String test(Locale locale, Model model) {访问test.do