SpringMVC_視圖解析器與中文亂碼問題
阿新 • • 發佈:2018-05-28
amp .org ava equal map xml配置 登錄 UC ans
return "/pages/front/success.jsp";
return "/pages/front/fail.jsp";
這兩句的結構是: 前綴(prefix)+變化值+ 後綴(suffix)
前綴是/pages/front/。後綴是.jsp
在springmvc.xml配置文件裏用視圖解析器配置前綴後綴,使return裏只有變化值: return "success";
springmvc.xml:
按住ctrl shift h,搜索internalResourceViewResolver,然後右鍵copy qualified name。粘貼到class中。
<?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-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd "> <!-- 配置包掃描 --> <context:component-scan base-package="cn.java.controller"></context:component-scan> <!-- 加入springmvc特有的註解驅動 --> <mvc:annotation-driven></mvc:annotation-driven> <!-- 視圖解析器 --> <!--prefix:前綴--> <!-- suffix:後綴--> <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/pages/front/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>
java:
@RequestMapping(value="test1") public String test1(String username,String password) { if("admin".equals(username)&&"123".equals(password)) { //登錄成功 return "success"; } else { //登錄失敗 System.out.println(username); return "fail"; } }
這裏實際return的就是/pages/front/success.jsp
SpringMVC_視圖解析器與中文亂碼問題