【问题标题】:Not able to read data send by controller on jsp无法读取控制器在jsp上发送的数据
【发布时间】:2014-04-02 13:12:33
【问题描述】:

我正在尝试从我的控制器通过 jsp 发送数据并尝试使用 Spring EL 读取它,但我无法做到。

控制器:

 @RequestMapping("/home")
    public String StudentHome(RedirectAttributes ra){
        String msg="mydata";
        ra.addFlashAttribute("msg", msg);
        return "home";
 }

jsp:

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
    ${msg}
</body>
</html>

我还需要包含其他内容吗?

【问题讨论】:

  • 你在类中添加了@Controller注解吗?
  • 是的,我有 @Controller 类注解

标签: java spring jsp spring-mvc


【解决方案1】:

RedirectAttribute 仅在您重定向时使用。尝试使用return "redirect:home"; -BCP

【讨论】:

    【解决方案2】:
    1. @RequestMapping注解上方添加@Controller注解

    2. controller-spring-beans.xml 中为您的控制器制作一个bean。

    示例

    <bean name="yourController"
    
        class="your.package">
    
        <property name="successView" value="path/to/your.jsp" />
    
    </bean>
    

    了解Spring here

    【讨论】:

    • 我有 @Controller 类注解。
    • 你添加了像我一样的bean吗?
    • 不,我没有。如果我使用注释,那么创建 bean 有什么用。你能告诉我吗,因为我不知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 2012-11-28
    • 2020-09-24
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    相关资源
    最近更新 更多