<?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>mn_spring_mvc_template</display-name>
<servlet>
<servlet-name>template</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>template</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:ApplicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd"
default-autowire="byName">
</beans>
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd"
default-autowire="byName">
<context:component-scan base-package= "mn.spring.mvc.template.controller.*" />
<bean id= "jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "viewClass" value ="org.springframework.web.servlet.view.JstlView" />
<property name= "prefix" value = "/view/" />
<property name= "suffix" value = ".jsp" />
</bean>
</beans>
@Controller
@RequestMapping("/controllertest")
public class SpringMvcTemplateController {
public SpringMvcTemplateController() {
}
@RequestMapping("/shows")
public String showTemplate() {
System.out.println("show_template");
return "template";
}
}
page: (1) WebContent/index.jsp
(2) WebContent/view/template.jsp
pageUrL : http://127.0.0.1:8080/mn_spring_mvc_template/controllertest/shows.do
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
在controller的方法里面打日志,后台查不到日志信息,应该是没进controller的缘故吧?如果是这个问题的话,想问熟悉这一块的朋友这个会是什么原因造成,spring接收到request后,不传进controller呢?
你在哪里装载的?web.xml看不到啊?
你该在web里面加载<spanstyle="font-size:9px;">template-servlet.xml
<spanstyle="color:#E53333;font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><propertyname="prefix"value="/view/"/>
<spanstyle="font-size:14px;line-height:22px;">这样?还是这样?
<spanstyle="font-size:14px;line-height:22px;"><spanstyle="color:#E53333;font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><propertyname="prefix"value="view/"/>
应该是注解没加好吧.
<preclass="brush:xml;toolbar:true;auto-links:false;"><beansxmlns="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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><preclass="brush:xml;toolbar:true;auto-links:false;"><!--添加注解驱动--> <mvc:annotation-driven/>试了一下,也不是注解的问题呢,呵呵你先运行这个地址<spanstyle="font-family:幼圆,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> <arel="nofollow">http://127.0.0.1:8080 看tomcat启动了没
在运行这个<spanstyle="font-family:幼圆,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> <arel="nofollow">http://127.0.0.1:8080/mn_spring_mvc_template 看行不
在运行这个<spanstyle="font-family:幼圆,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> <spanstyle="font-family:幼圆,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> <arel="nofollow">http://127.0.0.1:8080/mn_spring_mvc_template/controllertest/shows.do
<spanstyle="font-family:幼圆,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">
<spanstyle="font-family:幼圆,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><spanstyle="font-family:幼圆,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">publicSpringMvcTemplateController(){
<spanstyle="font-family:幼圆,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> }把这个去掉看下
<spanstyle="color:#FF6600;font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;">加了也没有想过呢,我印象中之前写的也没加也能用哦..?
<spanstyle="color:#FF6600;font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><spanstyle="color:#000000;">你能告诉我你的springmvc版本多少吗?你曾经springmvc多少版本?
<spanstyle="color:#FF6600;font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><spanstyle="color:#000000;">我可以告诉你的是: <mvc:annotation-driven/>要加的
<spanstyle="color:#FF6600;font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><spanstyle="color:#000000;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><!--启动注解驱动的SpringMVC功能,注册请求url和注解POJO类方法的映射-->
<spanstyle="line-height:normal;">换句话说就是如果木有这个,你的注解urlpojo相当于失败、正好你的404说明url根本木有被处理、
<spanstyle="color:#FF6600;font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><spanstyle="color:#000000;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;">官方的最减配置如下:
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;">
<preclass="brush:xml;toolbar:true;auto-links:false;"><?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><mvc:annotation-driven/></beans><spanstyle="color:#E53333;"><mvc:annotation-driven/><spanstyle="color:#E53333;">来自上面的头文件声明,所以你要声明头文件,你上面的配置木有、<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;">官方的解释:<arel="nofollow">http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-config
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;">
<spanstyle="color:#FF6600;font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;"><spanstyle="color:#000000;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;line-height:normal;background-color:#FFFFFF;">
<spanstyle="color:#E53333;font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:normal;background-color:#FFFFFF;color:#64451D;">检查下Controller在这个包下面么?
logdebug出来的信息是“NomappingfoundforHTTPrequestwithURI”,好奇怪的问题。
[QC]DEBUG[http-bio-8080-exec-3]org.springframework.web.servlet.DispatcherServlet.doService(823)|DispatcherServletwithname'template'processingGETrequestfor[/mn_spring_mvc_template/controllertest/shows.do]
[QC]DEBUG[http-bio-8080-exec-3]org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(209)|Lookinguphandlermethodforpath/controllertest/shows.do<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> }
<spanstyle="font-size:14px;line-height:22px;">方法加上request和response参数试试~
请求没进controller,加上了request/response参数也查不出东西(已测试)。