【发布时间】:2026-02-04 17:50:01
【问题描述】:
我是 spring 新手,我需要帮助。
我的工作解决问题 步骤
1:创建了一个控制器,我在控制器中创建了5个Bean类对象
2:创建的HashMap。
3:将bean类对象添加到HashMap中。
4:将HashMap添加到模型对象中。
5:在 Jsp 中我想检索 bean 类对象并在 jsp 中打印 bean 类属性值(成功视图)。
public class SocialMediaContoller{//step1
//step2
TwitterBean tb=new sampleA();
GoogleBean gb=new GoogleBean();
YouTubeBean yb=new YouTubeBean();
InstagramBean ib=new InstagramBean();
FaceBookBean fb=new FaceBookBean();
//step3
Map<String,Object> socialmedia=new HashMap<String,Object>();
socialmedia.put("twittermetrics",tb);
socialmedia.put("googleplusmetrics",gb);
socialmedia.put("instagrammetrics",ib);
socialmedia.put("youtubemetrics",yb);
socialmedia.put("facebookmetrics",fb);
//spe4
return "view/socialmedia/SocialMediaSuccess";
}
InSuccessJSP 第6步: 我想显示 bean 类属性的值 我的代码是:
<div id="twitter">
<div id="twitterMetrics">
<p><b>Twitter Profile Analysis</b></p>
<table id="twitterTable">
<tr>
<td><b>Followers</b></td>
<td><c:out value="${tb.followers}" /></td>
</tr>
</tr>
</table>
<table id="googleTable">
<tr>
<td><b>Followers</b></td>
<td><c:out value="${gb.followers}" /></td>
</tr>
</tr>
</table>
<table id="youtubeTable">
<tr>
<td><b>Followers</b></td>
<td><c:out value="${yb.views}" /></td>
</tr>
</tr>
</table>
<table id="instagarmTable">
<tr>
<td><b>Followers</b></td>
<td><c:out value="${ib.followers}" /></td>
</tr>
</tr>
</table>
</div>
</div>
其余对象相同
在 JSP 中
最后我需要帮助/代码在 (Step6)从 MapObject(即社交媒体)从 JSP 成功页面中的模型对象检索元素
【问题讨论】:
标签: java spring jsp hashmap jstl