jsp中如何通过accessbean从DB中获取数据
添加到数据库(提交数据)后,在我的AccessBean中没有获取最新插入的数据。但是当我再次回到jsp时,数据就可用了。我不知道如何解决这个问题。
下面是提交数据后在cmdImpl中插入的代码
AddressAccessBean add = new AddressAccessBean(Long.parseLong(memberid),shipid);
shipBean.setInitKey_ShipToCodeName(shipid);
add.setAddressField2(shipBean.getName()+shipBean.getCity()+shipBean.getState());
add.setAddressField1("WD");
add.setMemberId(memberid);
add.setAddressField3(shipid);
add.setStatus("P");
add.commitCopyHelper();
。尝试通过accessbeans及其finder方法在jsp上获取数据并显示到jsp中的表中
<%
String[] member_Id = (String[])request.getAttribute("memberid");
String memberId=member_Id[0];
AddressAccessBean add = new AddressAccessBean();
java.util.Enumeration enu = add.findByMemberId(Long.parseLong(memberId));
while (enu.hasMoreElements()) {
AddressAccessBean as = (AddressAccessBean) enu.nextElement();
if (as.getAddressField3() != null && as.getAddressField1().equals("WD")) {
com.ibm.commerce.extension.objects.xShipToCodeAccessBean bb = new com.ibm.commerce.extension.objects.xShipToCodeAccessBean().findByShipToCodeName(as.getAddressField3());
%>
<TR>
<Td ALIGN="LEFT" width="20%"><%=as.getAddressField2()%></Td>
<Td ALIGN="LEFT" width="20%"><%=bb.getName()%></Td>
<Td ALIGN="LEFT" size="15%"><%=bb.getShipToCodeName()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getCity()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getState()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getSoldTo()%>
</Td>
After adding the to the db (commiting the data), not getting the latest inserted data in my AccessBean. But when I come backto the jsp again the data is available. I don't know how to resolve the issue.
Below is the insert code in cmdImpl
AddressAccessBean add = new AddressAccessBean(Long.parseLong(memberid),shipid);
shipBean.setInitKey_ShipToCodeName(shipid);
add.setAddressField2(shipBean.getName()+shipBean.getCity()+shipBean.getState());
add.setAddressField1("WD");
add.setMemberId(memberid);
add.setAddressField3(shipid);
add.setStatus("P");
add.commitCopyHelper();
After commiting the data.trying to fetch data on jsp through accessbeans and their finder methods and displaying into table in jsp
<%
String[] member_Id = (String[])request.getAttribute("memberid");
String memberId=member_Id[0];
AddressAccessBean add = new AddressAccessBean();
java.util.Enumeration enu = add.findByMemberId(Long.parseLong(memberId));
while (enu.hasMoreElements()) {
AddressAccessBean as = (AddressAccessBean) enu.nextElement();
if (as.getAddressField3() != null && as.getAddressField1().equals("WD")) {
com.ibm.commerce.extension.objects.xShipToCodeAccessBean bb = new com.ibm.commerce.extension.objects.xShipToCodeAccessBean().findByShipToCodeName(as.getAddressField3());
%>
<TR>
<Td ALIGN="LEFT" width="20%"><%=as.getAddressField2()%></Td>
<Td ALIGN="LEFT" width="20%"><%=bb.getName()%></Td>
<Td ALIGN="LEFT" size="15%"><%=bb.getShipToCodeName()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getCity()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getState()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getSoldTo()%>
</Td>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您转发到 JSP,则通过实体/访问 bean 插入的数据对于查找器查询将不可见。即,如果您转发到 JSP 而不是重定向,则事务仅在执行 JSP 后才会提交。提交事务后,实体 bean 更改将写入数据库。这就是为什么您在尝试使用查找器查询时无法看到插入的原因。
您有两个选择:-
If you are fowarding to the JSP, data inserted through entity/access beans will not be visible to a finder query. i.e., if you are forwarding to a JSP instead of a redirect, transaction gets committed only after the execution of JSP. Entity bean changes are written to db after transaction is committed. Thats is why you are not able to see the insert while trying to use a finder query.
You have two options :-