Struts2框架下JSP向Action传值失败

绝对密位 2017-12-05 05:05:12
user_modified.jsp
//只贴出了form部分

<form action="/account/save">
<a onclick="unlocked()">Unlock</a>
<label for="userid">userid: </label>
<input type="text" name="user.userid" id="userid" value="${user.userid}" disabled><br>
<label for="username">username: </label>
<input type="text" name="user.username" id="username" value="${user.username}" disabled><br>
<label for="password">password: </label>
<input type="password" name="user.password" id="password" value="${user.password}" disabled><br>
<c:if test="${sessionScope.identified=='1'}">
<c:if test="${user.identified=='0'}">
<label for="user">user: </label>
<input type="radio" name="user.identified" value="0" id="user" checked disabled>
<label for="manager">manager:</label>
<input type="radio" name="user.identified" value="1" id="manager" disabled>
</c:if>
<c:if test="${user.identified=='1'}">
<label for="user">user: </label>
<input type="radio" name="user.identified" value="0" id="user" disabled>
<label for="manager">manager:</label>
<input type="radio" name="user.identified" value="1" id="manager" checked disabled>
</c:if>
</c:if>
<c:if test="${sessionScope.identified=='0'}">
<input type="hidden" name="user.identified" value="${user.identified}">
</c:if>
<br>
<input type="submit" value="提交">
<input type="button" value="返回" onclick="window.location.href='/account/show';">
</form>


提交到的Action
AccountAction.save()


public String save() {
if (user.getUserid() == null) {
return register();
} else {
return updateById();
}
}


AccountAction.UpdateById()

public String updateById() {
//在这里设断点发现就没有user这个对象
String querySql = "SELECT * FROM tb_user WHERE user_pk_userid=?";
String[] row = JdbcUtil.executeSQL(querySql, user.getUserid()).get(0);
if (row != null) {
String sql = "UPDATE tb_user SET user_username=?, user_password=?, user_identified=? WHERE user_pk_userid=?";
String username = this.user.getUsername() == null || "".equals(this.user.getUsername().trim()) ? row[1] : this.user.getUsername();
String password = this.user.getPassword() == null || "".equals(this.user.getPassword().trim()) ? row[2] : this.user.getPassword();
String identified = this.user.getIdentified() == null || "".equals(this.user.getIdentified().trim()) ? row[3] : this.user.getIdentified();
if (JdbcUtil.updateSQL(sql, username, password, identified, row[0]) == 1) {
return "success";
}
}
return "failed";
}


不知道为什么,注册都没问题,就修改信息保存的时候出现空指针异常,然后断点就发现是user对象没传过来,有谁晓得这是为啥么
...全文
195 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
vswen5 2017-12-06
  • 打赏
  • 举报
回复
struts2 action跳action不是这样的写法
李时水 2017-12-05
  • 打赏
  • 举报
回复
先引入user所在的包,然后new出一个新的对象,然后用set get方法获得
绝对密位 2017-12-05
  • 打赏
  • 举报
回复
引用 1楼aa562256325 的回复:
先引入user所在的包,然后new出一个新的对象,然后用set get方法获得
struts框架的话user对象应该在值栈里,action类中设置了set和get方法他应该会自动获取这个user对象,不然登录和注册为啥能成功

81,091

社区成员

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

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