package sunyangovo;
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;
@Controller
@RequestMapping("/system")
public class Conn {
@RequestMapping(value="https://bbs.csdn.net/index",method=RequestMethod.GET)
public ModelAndView index(ModelAndView model) {
// TODO Auto-generated constructor stub
model.setViewName("system/index");
model.addObject("name","sadwad");
return model;
}
}
web.xml:
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<!-- 中文亂碼處理 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring組態檔資訊 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring/applicationContext.xml</param-value>
</context-param>
<!-- ContextLoaderListener監聽器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 日志配置 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:config/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 配置前端控制器 -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/springmvc/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/errors/404.jsp</location>
</error-page>
<error-page>
springmvc.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"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<!-- 只需要掃描包中的 Controller 注解 -->
<context:component-scan base-package="com.ischoolbar.programmer.controller">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 啟動 mvc 注解驅動 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 啟動定時任務 -->
<task:annotation-driven/>
<!-- 靜態資源處理 -->
<mvc:default-servlet-handler/>
<!-- 配置視圖決議器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="https://bbs.csdn.net/WEB-INF/views/"></property>
<property name="suffix" value="https://bbs.csdn.net/topics/.jsp"></property>
</bean>
<!-- 檔案上傳 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 上傳檔案大小限制 -->
<property name="maxUploadSize">
<value>10485760</value>
</property>
<!-- 請求的編碼格式, 和 jsp 頁面一致 -->
<property name="defaultEncoding">
<value>UTF-8</value>
</property>
</bean>
</beans>
index:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
response.sendRedirect("system/index");
%>
uj5u.com熱心網友回復:
各種方法都試過了 但就是一直404uj5u.com熱心網友回復:
views目錄下直接放jsp的檔案呀,為什么要加system目錄呢把jsp檔案放在了system,這不在springmvc.xml配的試圖決議器起沖突了嗎。。。uj5u.com熱心網友回復:
應該是這位老兄所說的,修改目錄試試uj5u.com熱心網友回復:
把system刪了 把jsp檔案直接放views里就行了uj5u.com熱心網友回復:
1.檢查視圖決議器配置2.檢查tomcat默認路徑
uj5u.com熱心網友回復:
404代表服務沒有回應吧轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/42849.html
標籤:Eclipse
上一篇:這是我的eclipse沒有連接到資料庫嗎?有人知道怎么解決嗎?
下一篇:強制轉換
