问题描述
- SpringMvc无法访问后台
- web.xml
<?xml version=""1.0"" encoding=""UTF-8""?>
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"">
<!-- 字符过滤转码(防止添加到数据库中的数据为乱码) -->characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8forceEncoding
truecharacterEncodingFilter
/*UrlRewriteFilter
org.tuckey.web.filters.urlrewrite.UrlRewriteFilterUrlRewriteFilter
/*<!-- 配置上下文 --><context-param> <param-name>contextConfigLocation</param-name> <!-- 利用上下文配置 --> <param-value>classpath:applicationContext*.xml</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><!-- Spring Mvc配置 --><servlet> <servlet-name>springmvc</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern></servlet-mapping><servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css</url-pattern></servlet-mapping><servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern></servlet-mapping><servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.html</url-pattern></servlet-mapping><servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css</url-pattern></servlet-mapping><servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.ftl</url-pattern></servlet-mapping><!-- log4j配置 --> <context-param> <param-name>webAppRootKey</param-name> <param-value>webName.root</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>WEB-INF/log4j.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>3000</param-value> </context-param>
springmvc-servlet.xml <?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:mvc=""http://www.springframework.org/schema/mvc"" 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.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd""> <!-- 启动扫描所有的controller --> <context:component-scan base-package=""com"" /> <!-- 主要作用于@Controller,激活该模式 下面是一种简写形式,完全可以手动配置替代这种简写形式; 它会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean 是spring MVC为@Controllers分发请求所必须的 --> <mvc:annotation-driven /> <!-- 公共映射配置 --> <mvc:view-controller path=""/"" view-name=""index"" /> <!-- jsp页面解析器,当Controller返回XXX字符串时,先通过拦截器,然后该类就会在/WEB-INF/views/目录下,查找XXX.jsp文件--> <bean id=""viewResolver"" class=""org.springframework.web.servlet.view.InternalResourceViewResolver""> <property name=""viewClass"" value=""org.springframework.web.servlet.view.JstlView""></property> <property name=""prefix"" value=""/""></property> <property name=""suffix"" value="".jsp""></property> </bean> <!-- 异常解析器 --> <bean id=""simpleMappingExceptionResolver"" class=""org.springframework.web.servlet.handler.SimpleMappingExceptionResolver""> <property name=""exceptionMappings""> <props> <prop key=""org.springframework.web.multipart.MaxUploadSizeExceededException"">common/fileerror</prop> </props> </property> </bean> <bean id=""multipartResolver"" class=""org.springframework.web.multipart.commons.CommonsMultipartResolver""> <!-- set the max upload size100MB --> <property name=""maxUploadSize""> <value>104857600</value> </property> <property name=""maxInMemorySize""> <value>4096</value> </property> </bean> </beans>
package com.video.web;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;import com.video.model.Videotab;
import com.video.service.videoService;@Controller
@RequestMapping(""/video/*"")
public class videoControl {
@Resource
public videoService service;@RequestMapping( value=""select""method=RequestMethod.GET)public ModelAndView addtest(){ Videotab videotab= new Videotab(); videotab.setVedioid(88); List<Videotab> list=service.selectVideo(videotab); System.out.println(""id---""+list.get(0).getVedioid()+""/r""+""title----""+list.get(0).getVediotitle()); return null;}
}
解决方案
@RequestMapping(""/video/*"")改成@RequestMapping(""video"")
解决方案二:
修改下springmvc的配置路径为/*
<servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/*</url-pattern></servlet-mapping>
解决方案三:
Tomcat启动正常吗?调试下呗。