在jsp页面中找不到的控制器传递的对象

时间:2012-10-25 13:24:15

标签: java spring jsp spring-mvc jstl

我正在开发一个简单的spring mvc web应用程序,我有: 一个简单的控制器:

public class LoginController extends MultiActionController {
    private final static String VIEW_LOGIN = "/login";


    public ModelAndView handleLogin(HttpServletRequest request,
            HttpServletResponse response){
        ModelAndView mv = new ModelAndView(VIEW_LOGIN);
        String prova = "PROVA123";
        mv.addObject(prova);
        return mv;
    }
}

一个简单的jsp页面:

<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>   

    <title>Login - Gestione Studenti</title>

    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>

  <body>
    <p><c:out value="${prova}"/></p><br>
  </body>
</html>

这是调度程序servlet xml文件

<bean id="loginController" class="it.mediosoft.gestionestudenti.web.LoginController">
        <property name="methodNameResolver" ref="handlerResolver"/>
    </bean>

    <bean id="urlMapping"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/login.html">loginController</prop>
            </props>
        </property>
    </bean>

    <bean id="handlerResolver"
        class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
        <property name="mappings">
            <props>
                <prop key="/login.html">handleLogin</prop>
            </props>
        </property>
    </bean>
     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
    </bean>

为什么在login.jsp中我不能使用loginController在ModelAndView中返回的对象? “c:out”没有打印任何东西....任何建议?

1 个答案:

答案 0 :(得分:0)

尝试:

mv.addObject("prova",prova);

应解决您的问题