MyInfo.java
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:3k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.opensource.blog.web.action;
  2. import javax.servlet.http.*;
  3. import org.apache.commons.beanutils.*;
  4. import org.apache.struts.action.*;
  5. import com.opensource.blog.comm.BlogUtil;
  6. import com.opensource.blog.exception.*;
  7. import com.opensource.blog.model.*;
  8. import com.opensource.blog.service.*;
  9. import com.opensource.blog.web.form.*;
  10. import com.opensource.blog.web.servlet.*;
  11. public class MyInfo
  12.     extends BaseAction {
  13.   private UserInfoService userInfoService;
  14.   public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
  15.                                HttpServletRequest servletRequest,
  16.                                HttpServletResponse servletResponse) {
  17.     ActionMessages errors = new ActionMessages();
  18.     MyInfoForm form = (MyInfoForm) actionForm;
  19.     UserSession us = this.getUserSession(servletRequest);
  20.     if (form.getAction().equalsIgnoreCase("show")) {
  21.       form.setAction("edit");
  22.       form.setAddress(us.getUserInfo().getAddress());
  23.       form.setAge(us.getUserInfo().getAge());
  24.       form.setCity(us.getUserInfo().getCity());
  25.       form.setEdulevel(us.getUserInfo().getEdulevel());
  26.       form.setEmail(us.getUserInfo().getEmail());
  27.       form.setFace(us.getUserInfo().getFace());
  28.       form.setIncome(us.getUserInfo().getIncome());
  29.       form.setIndustry(us.getUserInfo().getIndustry());
  30.       form.setMb(us.getUserInfo().getMb());
  31.       form.setNickname(us.getUserInfo().getNickname());
  32.       form.setPro(us.getUserInfo().getPro());
  33.       form.setSex(us.getUserInfo().getSex());
  34.       form.setSign(us.getUserInfo().getSign());
  35.       form.setWork(us.getUserInfo().getWork());
  36.       return actionMapping.findForward("myinfo");
  37.     }
  38.     if (form.getAction().equalsIgnoreCase("edit")) {
  39.       UserInfo ui = us.getUserInfo();
  40.       try {
  41.         BeanUtils.copyProperties(ui, form);
  42.       }
  43.       catch (Exception e) {
  44.       }
  45.       try {
  46.         ui = this.getUserInfoService().saveUserInfo(ui);
  47.       }
  48.       catch (BlogException ex) {
  49.         errors.add("error.myinfo.upinfo", new ActionMessage("error.myinfo.upinfo"));
  50.         saveErrors(servletRequest, errors);
  51.         return actionMapping.findForward("error");
  52.       }
  53.       this.saveUserSession(servletRequest, ui);
  54.       ActionForward f = new ActionForward(BlogUtil.getResultUrl("info.up.well", "myInfo.do"), true);
  55.       return f;
  56.     }
  57.     return actionMapping.findForward("error");
  58.   }
  59.   public UserInfoService getUserInfoService() {
  60.     return userInfoService;
  61.   }
  62.   public void setUserInfoService(UserInfoService userInfoService) {
  63.     this.userInfoService = userInfoService;
  64.   }
  65. }