这是错误:
<bean:define id="myid" value="<%=request.getAttribute("key")%>"
但后面加上强制转换(字符串)就可以了:
<bean:define id="myid" value="<%=(String)request.getAttribute("key")%>"
还有什么。跟着就可以了。
this is <%=request.getAttribute("key")%>
为什么?
最佳答案
request.setAttribute("key","value as Object")
存储为 Object
的值(注意大 O),因此当您检索 request 时.getAttribute("key")
它以 Object 类型返回,因此您需要对其进行强制转换。
关于java - 为什么在使用 struts 时有时需要强制转换 request.getAttribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23128429/