我有一个 Servlet,它处理来自 Web 的一些内容并生成一个字符串值。我需要在 html 页面的表标记内显示此字符串值。
如何使用 setAttribute 方法和 getrequestdispatcher 方法从 servlet 传递此字符串值?
谢谢
阿布舍克小号
In your Servlet
,将数据设置为属性request
:
RequestDispatcher dispatcher = request.getRequestDispatcher("yourJspPage.jsp");
request.setAttribute("Name", "Temp"); // set your String value in the attribute
dispatcher.forward( request, response );
In your jsp
页面,访问request
像这样的属性:
<table>
<tr>
<td><%=request.getAttribute("Name")%></td>
</tr>
</table>
希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)