struct2框架jsp页面传参失败

发布于 2022-09-02 15:07:03 字数 496 浏览 26 评论 0

jsp页面对象方式传参进action中,在action中定义了getter、setter方法,但是还是取不到值!

clipboard.png

clipboard.png

但是提示结果为空:

clipboard.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蒲公英的约定 2022-09-09 15:07:03

有写form么?html页面中

修改答案:

在文件头添加 <%@ taglib prefix="s" uri="/struts-tags"%>
输入框写成 <s:textfield id="userid" name="user.userid"/> 写成类似这样的

继续修改答案:

运行你的项目我发现,在添加 flower 时候,控制台报错

Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.xhydxs.action.AdminUserAction] to required type [com.xhydxs.entity.AdminUser] for property 'adminUser': no matching editors or conversion strategy found

可以发现是类型转化问题,为什么你会让 AdminUserAction 转化成 AdminUser 呢?于是我使用全局查找 AdminUserAction 和 AdminUser【用 Atom 编辑器】。终于让我发现!

applicationContext.xml 文件中:

    <bean name="adminUser" class="com.xhydxs.action.AdminUserAction"
        scope="prototype">
        <property name="adminUserBiz" ref="adminUserBiz" />
    </bean>

*.hbm.xml 文件中:

    <many-to-one name="adminUser" class="com.xhydxs.entity.AdminUser" fetch="select">
        <column name="UPD_OPR" length="20" not-null="true" />
    </many-to-one>

发现了么?name 都是 adminUser,然而 class 分别对应着AdminUserAction和AdminUser。然后把 AdminUserAction 对应的name改掉就行了。。。。至于为什么上面这个错误会导致goods为null,因为你在Goods类里有一个AdminUser成员变量,导致struts就没法构建goods这个实例了>3<

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文