关于SpringMvc配置的问题

doublecake 2015-05-29 01:51:17
我想要在controller 层处理后返回一个html页面,并在html页面中使用el表达式,请问如何做?下面贴出我的spring-mvc.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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
">

<!-- 视图解析-->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/" p:suffix=".jsp" />

<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="utf-8" />


<bean id="stringConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>

<!-- JSON视图-->
<bean id="jsonConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="stringConverter"/>
<ref bean="jsonConverter" />
</list>
</property>
</bean>
</beans>



还请大神不吝赐教~~
...全文
398 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
二十亩鱼 2015-06-03
  • 打赏
  • 举报
回复
就一楼
Inhibitory 2015-05-31
  • 打赏
  • 举报
回复
html不支持EL表达式
tragedyxd 2015-05-31
  • 打赏
  • 举报
回复
楼上1楼正解
光光-Leo 2015-05-31
  • 打赏
  • 举报
回复
你配置文件中有 p:suffix=".jsp",说明只会返回jsp页面,你把这个去掉,不设置后缀,在controler中定义页面路径时加后缀,比如: private static String START="module/start.jsp"; 或者 private static String START="module/start.html"; 这样既可以返回html,也可以返回jsp
枫醉秋 2015-05-29
  • 打赏
  • 举报
回复
你配置文件中配置的是*.jsp,不能直接放回*.html的,只能返回一个*.jsp
qq_25343429 2015-05-29
  • 打赏
  • 举报
回复
在xml里添加个注解,注:base-package里面是你自己用到注解的类的所在包

	<!-- 扫描注解,使注解生效 -->
	<context:component-scan base-package="com.web.controller"></context:component-scan
	<mvc:annotation-driven/>
在controller里

@Controller
public class MyController {
    @RequestMapping("/index")
    public String index(){
        return "index";
    }
}
用el的话,要导jstl的包,还要在页面最上声明: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧