maven加springmvc搭建web项目一直提示404页面,求解惑
web.xml代码如下
spring.xml
spring-mvc.xml
controller层代码
需要贴pom文件么。我觉得可能是我spring配置错误了。求指点
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" 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" xsi:schemaLocation="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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="com.spring.web.gameCenter.controller" />
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
</list>
</property>
</bean>
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 自动扫描(自动注入) -->
<mvc:resources location="WEB-INF/Back/" mapping="WEB-INF/Back/**" />
<mvc:resources location="/assets/" mapping="/assets/**" />
<!-- 视图渲染 jsp/freemaker/velocity-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 制定页面存放的路径 -->
<property name="prefix" value="/WEB-INF/Back/"></property>
<!-- 文件的后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding">
<value>UTF-8</value>
</property>
<property name="maxUploadSize">
<value>32505856</value><!-- 上传文件大小限制为31M,31*1024*1024 -->
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
</bean>
</beans>
spring.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: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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<!-- Dubbo服务接口引用 -->
<import resource="classpath:spring/dubbo/dubbo-consumer.xml"/>
</beans>spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" 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" xsi:schemaLocation="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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="com.spring.web.gameCenter.controller" />
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
</list>
</property>
</bean>
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 自动扫描(自动注入) -->
<mvc:resources location="WEB-INF/Back/" mapping="WEB-INF/Back/**" />
<mvc:resources location="/assets/" mapping="/assets/**" />
<!-- 视图渲染 jsp/freemaker/velocity-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 制定页面存放的路径 -->
<property name="prefix" value="/WEB-INF/Back/"></property>
<!-- 文件的后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding">
<value>UTF-8</value>
</property>
<property name="maxUploadSize">
<value>32505856</value><!-- 上传文件大小限制为31M,31*1024*1024 -->
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
</bean>
</beans>
controller层代码
package com.spring.web.gameCenter.controller;
import java.io.IOException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@Controller
@RequestMapping("/adminController")
public class UserController {
@RequestMapping(value="index")
public String index() {
return "index";
}
@RequestMapping("index_v1")
public String index_v1() {
return "index_v1";
}
@RequestMapping("login")
public String login() {
return "login";
}
@RequestMapping("user")
public String user() {
return "user";
}
@RequestMapping("list")
@ResponseBody
public String list(String search,Integer offset,Integer limit,String sort,String order,String filter) throws IOException {
JSONObject jsonObject = new JSONObject(true);
return JSON.toJSONString(jsonObject);
}
@RequestMapping(value = "/testRestful/{id}", method = { RequestMethod.DELETE })
public String testRestfulDelete(Integer id) {
System.out.println("The value which the restful style url is DELETE :"
+ id);
return "success";
}
@RequestMapping(value = "/testRestful/{id}", method = { RequestMethod.PUT })
public String testRestfulPut(Integer id) {
System.out.println("The value which the restful style url is PUT :"
+ id);
return "success";
}
}
需要贴pom文件么。我觉得可能是我spring配置错误了。求指点
...全文
相关推荐
解决idea导入ssm项目启动tomcat报错404的问题
今天小编就为大家分享一篇解决idea导入ssm项目启动tomcat报错404的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
maven入门整合SpringMVC登录+调用天气接口实例
最近在学习maven搭建Spring,java调用接口。写了个这样的小项目,分享一下,共同进步。
maven+SpringMvc+Mybatis+shiro安全框架整合实例(-)
maven+SpringMvc+Mybatis+shiro安全框架整合实例(-)
springMVC项目实例
java springMVC完整项目实例加mybatis,修改连接数据库地址可直接运行
ssm框架的搭建与使用
实训内容:Maven环境搭建、Spring的应用、SpringMVC的应用、MyBtis的使用


Web 开发
