4
回答
springmvc项目,jsp无法j解析,直接在页面打印jsp代码
极速云服务器,低至1.04元/天>>>   

我配置了一个spring+mybatis的项目,jsp代码是放在了WEB-INF文件夹下面,通过modelandview返回到jsp。下面是我的spring-mvc的配置文件。

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.1.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">


<!-- 自动扫描controller -->
<context:component-scan base-package="cuteshop.sys.controller" />
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />


<!-- 上传文件 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8" />
<property name="maxInMemorySize"  value="4096000" />
<property name="maxUploadSize" value="10485760000"/>
</bean>


<!-- spring视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:default-servlet-handler/>
<!-- 避免IE在ajax请求时,返回json出现下载 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<!--先不配置,采用默认配置-->
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property> 
</bean>
</beans>

测试的controller

package cuteshop.sys.controller;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


import cuteshop.com.core.PageUtil;
import cuteshop.sys.entity.UserInfo;
import cuteshop.sys.facade.UserinfoFacade;


@Controller
@RequestMapping("/test")
public class TestConroller {
@Autowired
private UserinfoFacade userinfoFacade;



@RequestMapping("/aap")
public ModelAndView getTest(){
ModelAndView mav = new ModelAndView();
mav.setViewName("test");
return mav;
}

@RequestMapping("/searchUser")
@ResponseBody
public PageUtil search(UserInfo userinfo,PageUtil pu){
pu.setQueryObj(userinfo);//设置查询条件
List<UserInfo> data = userinfoFacade.searchUser(pu);
pu.setData(data);//设置反馈结果
return pu;

}


返回之后直接在浏览器上打印了jsp的代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>娴嬭瘯椤甸潰</title>
</head>
<body>
	<h3>aaaaa</h3>
</body>
</html>
请教是什么情况,多谢。

举报
顶部