如何将对象从视图传递到java函数?
我有一个jsp页面如何将对象从视图传递到java函数?,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,我有一个jsp页面 <%@page import="org.springframework.web.servlet.ModelAndView"%> <%@page import="mvc3.helpers.Utils"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://j
<%@page import="org.springframework.web.servlet.ModelAndView"%>
<%@page import="mvc3.helpers.Utils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>View Topic</title>
</head>
<body>
<fieldset>
<legend>${topic.getName()}</legend>
<div class="display-label-field"><b>Content:</b>${topic.getText()}</div>
<div class="display-label-field"><b>Comments count:</b>${topic.getCommentsCount()}</div>
<div class="display-label-field"><b>Last time updated:</b>${topic.getTimeLastUpdated()}</div>
</fieldset>
<p>
<%=Utils.actionLink("Comment Topic", "Topic", "AddComment", Integer.toString( topic.getId() ) ) %>
<%=Utils.actionLink("Back to Topic List", "", "home", null)%>
</p>
查看主题
${topic.getName()}
内容:${topic.getText()}
评论计数:${topic.getCommentScont()}
上次更新:${topic.getTimeLastUpdated()}
问题是,${topic.getName()}工作正常,但导致主题无法解决错误。如何处理此问题?如果您在请求中设置了属性主题,请执行以下操作
Integer.toString( ((Topic)request.getAttribute("topic")).getId())
如果您在请求中设置了属性topic,请执行以下操作
Integer.toString( ((Topic)request.getAttribute("topic")).getId())
我们不应该用EL访问getId吗?像下面这样的
Integer.toString( ${topic.getId()})
我们不应该用EL访问getId吗?像下面这样的
Integer.toString( ${topic.getId()})
尚未为视图模型设置变量“topic”
。在控制器中,您将需要类似以下内容:
myModelData.put("topic", topicId);
尚未为视图模型设置变量“topic”
。在控制器中,您将需要类似以下内容:
myModelData.put("topic", topicId);
几乎正确。我们需要使用完整的类型声明mvc3.model.Topic,而不是TopicOr,您可以做到几乎正确。我们需要使用完整的类型声明mvc3.model.Topic而不是TopicOr,您可以这样做