struts标签中不能用jsp脚本?高手帮忙!

chimingwei 2009-03-27 08:45:34
struts标签中不能用jsp脚本
例如<html:text property="username" value='<%=request.getAttribute("name1") %>'/>
这样就报错,是什么原因呢?希望高手指点啊。说说原理。
...全文
202 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
liang__ 2009-03-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 therehere 的回复:]
The method setValue(String) in the type BaseInputTag is not applicable for the arguments (Object)

text property="username" struts的标签看到这句话就去会翻译成
setUserName(String arguments)因为你的username一定是String类型的
从出错信息看 你用了object类型 作为 arguments
很明显 request.getAttribute("name1") 返回的是object
很明显你要的是一个String类型的arguments
setUserName(String arguments…
[/Quote]

强制类型转化一下试试。
<%=(String)request.getAttribute("name1") %>
不过《%=%》不就相当于输出语句了吗?

dadi5566 2009-03-28
  • 打赏
  • 举报
回复
关注中
therehere 2009-03-28
  • 打赏
  • 举报
回复
The method setValue(String) in the type BaseInputTag is not applicable for the arguments (Object)

text property="username" struts的标签看到这句话就去会翻译成
setUserName(String arguments)因为你的username一定是String类型的
从出错信息看 你用了object类型 作为 arguments
很明显 request.getAttribute("name1") 返回的是object
很明显你要的是一个String类型的arguments
setUserName(String arguments) 用Object 作为参数就报错了

注意request.getAttribute()
和 request。getParmeter()
是不同的返回类型
Sou2012 2009-03-28
  • 打赏
  • 举报
回复
enable el
liling8203 2009-03-28
  • 打赏
  • 举报
回复
按理说可以使用的
chimingwei 2009-03-28
  • 打赏
  • 举报
回复
我也知道用el表达式好使,但是为什么不能用jsp语句呢?
redlotus_lyn 2009-03-27
  • 打赏
  • 举报
回复
<html:text property="username" value="${name1}"/>
chimingwei 2009-03-27
  • 打赏
  • 举报
回复
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 20 in the jsp file: /login.jsp
The method setValue(String) in the type BaseInputTag is not applicable for the arguments (Object)
17: <bean:write name="chi"/>
18: ${chi[1] }
19: <html:form action="login.do" method="post">
20: username : <html:text property="username" value='<%=request.getAttribute("name1") %>'/><html:errors property="username"/><br/>
21: password : <html:password property="password"/><html:errors property="password"/><br/>
22:
23: <html:submit/><html:cancel/>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.chi.myfilter.SetFilter.doFilter(SetFilter.java:23)

这是报错的信息
therehere 2009-03-27
  • 打赏
  • 举报
回复
报的是 什么错啊

81,077

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧