|
 
- 帖子
- 131
- 主题
- 0
- 精华
- 0
- 积分
- 203
- 疯狂金币
- 104
- 疯狂水晶
- 0
- 性别
- 男
- 在线时间
- 33 小时
|
问题背景:运用struts实现一个简单的注册功能。
jsp页面中,有爱好这一项,我运用multibox实现,如下:- 爱好:<br>
- 上网<html:multibox property="hobbies" value="上网"/>
- 旅游<html:multibox property="hobbies" value="旅游"/>
- 足球<html:multibox property="hobbies" value="足球"/>
- 围棋<html:multibox property="hobbies" value="围棋"/><hr>
复制代码 然后,我在register_61302.Action中,想把多个爱好字符串合成一个字符串存入数据库中。但改了之后,虽然不提示任何错误,但所有注册页面的数据都写不进数据库中了!!!百思不得其解,请各位大侠帮帮忙!
这是可以正常运行的代码。但若将被注释部分加进来(且去掉user.setHobbies(isToGB(register_61302Form.getHobbies()));)的话。便会出现那个费解的情况!
)- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- Register_61302Form register_61302Form = (Register_61302Form) form;// TODO Auto-generated method stub
-
- try{
- //生成实体类
- Emailuser61302 user = new Emailuser61302();
- //从form中获取数据
- user.setEmail(register_61302Form.getEmail());
- user.setPassword(register_61302Form.getPassword());
- user.setCity(isToGB(register_61302Form.getCity()));
- user.setEducation(isToGB(register_61302Form.getEducation()));
- user.setAge(register_61302Form.getAge());
- user.setSex(isToGB(register_61302Form.getSex()));
- user.setAddress(isToGB(register_61302Form.getAddress()));
- user.setIntroduction(isToGB(register_61302Form.getIntroduction()));
- //本来想存入所有的爱好,但不知道为什么竟然写不进数据库了。
- //Object obj=(register_61302Form.getHobbies());
- //String[] hobbyList=(String[])obj;
- //String hobbies = null;
- //for(int i=0;i<hobbyList.length;i++){
- // System.out.println(hobbyList);
- //hobbies+=hobbyList;
- //}
- //user.setHobbies(isToGB(hobbies));
-
- user.setHobbies(isToGB(register_61302Form.getHobbies()));
- user.setMobile(register_61302Form.getMobile());
- user.setEmailAddress(register_61302Form.getEmailAddress());
- //使用构造器实例化的dao
- Emailuser61302DAO dao= getDao();
- //开始事务
- Transaction tran = dao.getSession().beginTransaction();
- dao.save(user);
- //提交事务
- tran.commit();
- }catch(Exception e){}
- return mapping.findForward("success");
- }
-
- public static String isToGB(String src){
- String strRet = null;
- try{
- strRet = new String(src.getBytes("ISO_8859_1"),"GBK");
- }catch(Exception e){
- e.printStackTrace();
- }
- return strRet;
- }
- }
复制代码
[ 本帖最后由 ruralcpz 于 2010-4-12 18:45 编辑 ] |
|