我新建了users表和发表言论的一张表 messages 其中users中有字段名userid 和username,通过用户登录将username保存在了Session中,messages表中有对应的muserid,在发表新言论时,如何将登录保存的username 转变为 muserid保存到messages表中去 具体代码如下:
add方法:
public boolean addMessage(String title,int muserid,
String content,Date time) {
top.setTptitle(title);
top.setTpuserid(muserid);
top.setTpcontent(content);
top.setTptime(time);
comm.open();
comm.insert(top);
return true;
Strus 执行
public String execute(){
ta.addMessage(title, muserid, content,new java.util.Date());jsp界面
<form method="POST" action="addMessage.action" >
<div align="center">
<input type="hidden" name="mid" value="<%=mid%>"/>
<input type="hidden" name="userid" value="<%=username%>"/>
我刚学strus2 和hibernate ,所以想通过实例提高自己,求高人指点
add方法:
public boolean addMessage(String title,int muserid,
String content,Date time) {
top.setTptitle(title);
top.setTpuserid(muserid);
top.setTpcontent(content);
top.setTptime(time);
comm.open();
comm.insert(top);
return true;
Strus 执行
public String execute(){
ta.addMessage(title, muserid, content,new java.util.Date());jsp界面
<form method="POST" action="addMessage.action" >
<div align="center">
<input type="hidden" name="mid" value="<%=mid%>"/>
<input type="hidden" name="userid" value="<%=username%>"/>
我刚学strus2 和hibernate ,所以想通过实例提高自己,求高人指点
例如User对象,有userName,Password,....包含相应的get和set方法
在前台将输入的内容保存到User对象中,在后台Action中,直接通过Hibernate保存对象到数据库就可以了,
当然了还需要struts和hibernate的配置信息