先贴代码(由于字数限制,我把get、set方法不予显示,请脑补)
ManagerAction.java
补充下,BaseAction类定义如下
public class BaseAction extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware
@Controller
public class ManagerAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = 1L;
@Resource
private UserService userService;
private Long userId;
private String userCode;
private String userName;
private String userPassword;
private String confirmPassword;
private String companyName;
private String userEmail;
private String companyPostcode;
private String companyPrefecture;
private String companyAddress;
private String companyTelephone;
private String companyFax;
private String companyHomepage;
private Integer companyLicenseCount;
private String oldPassword;
private Date updateTime;
private String modifyPWDFlag;
private Integer identity;
public String create() {
try {
User user = new User();
user.setCode(userCode);
user.setName(userName);
String pwd = Utility.md5Encrypt(userPassword);
user.setPassword(pwd);
user.setEmail(userEmail);
Company company = new Company();
company.setCode(userCode);
company.setName(companyName);
company.setPostcode(companyPostcode);
company.setPrefecture(companyPrefecture);
company.setAddress(companyAddress);
company.setTelephone(companyTelephone);
company.setFax(companyFax);
company.setHomepage(companyHomepage);
company.setLicenseCount(companyLicenseCount);
user.setCompany(company);
user.setIdentity(Constant.USER_IDENTITY_COMADMIN);
userService.saveComAdmin(user);
return SUCCESS;
}catch(Exception e) {
addActionError(e.getMessage());
return ERROR;
}
}
managerRegister.jsp
<!-- 会社管理者新規作成画面 -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>会社管理者新規作成画面</title>
</head>
<body>
<br/>
<!-- <form id="manager" name="manager" action="managerRegister.action" method="post"> -->
<s:form name="admin" action="managerRegister" theme="simple" >
<s:hidden name="identity" value="1"></s:hidden>
<table>
<tr><td><label>ユーザID<span class="required"> * </span></label></td><td><s:textfield name="userCode" size="24" maxlength="24" required="true"/></td></tr>
<tr><td><label>ユーザ名</label></td><td><s:textfield label="ユーザ名" labelposition="left" name="userName" size="40" maxlength="100"/></td></tr>
<tr><td><label>パスワード<span class="required"> * </span></label></td><td><s:textfield label="パスワード" labelposition="left" name="userPassword" size="20" maxlength="20" required="true"/></td></tr>
<tr><td><label>確認パスワード</label></td><td><s:textfield label="確認パスワード" labelposition="left" name="confirmPassword" size="20" maxlength="20"/></td></tr>
<tr><td><label>会社名</label></td><td><s:textfield label="会社名" labelposition="left" name="companyName" size="40" maxlength="100"/></td></tr>
<tr><td><label>メールアドレス<span class="required"> * </span></label></td><td><s:textfield label="メールアドレス" labelposition="left" name="userEmail" size="40" maxlength="100" required="true"/></td></tr>
<tr><td><label>郵便番号</label></td><td><s:textfield label="郵便番号" labelposition="left" name="companyPostcode" size="20" maxlength="20"/></td></tr>
<tr><td><label>都道府県</label></td><td><s:textfield label="都道府県" labelposition="left" name="companyPrefecture" size="20" maxlength="20"/></td></tr>
<tr><td><label>住所</label></td><td><s:textfield label="住所" labelposition="left" name="companyAddress" size="20" maxlength="100"/></td></tr>
<tr><td><label>電話番号</label></td><td><s:textfield label="電話番号" labelposition="left" name="companyTelephone" size="20" maxlength="20"/></td></tr>