首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

增添角色—s

2012-10-09 
添加角色—sjsp:%@ page languagejava pageEncodingGBK%%@ taglib urihttp://struts.apache.org

添加角色—s
jsp:

<%@ page language="java" pageEncoding="GBK"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>

<title>新建角色</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath }/css/styles.css">
<script type="text/javascript">
//按钮操作
function doSubmit(o){
if(document.getElementById("role.roleName").value==""){
     alert("角色名不得为空!");
     return false;
     }
     document.forms[0].submit();
}
</script>
</head>

<body method="post">
<div onclick="javascript:history.go(-1);">
返回
</button>
<button onclick="javascript:doSubmit('doAdd');">
保存
</button>
</div>
<table border="0" cellPadding="3"
cellSpacing="0">
<tr>
<th maxlength="" />
</td>
<th maxlength="50" size="46" />
</td>
</tr>
<tr>
<th value="1" />
</td>
</tr>
</table>
</html:form>
</body>
</html:html>

actionForm:

/*
* Generated by MyEclipse Struts Template path: templates/java/JavaClass.vtl
*/
package com.accp.crm.web.form.role;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.accp.crm.model.SysRole;
import com.accp.crm.web.form.BaseForm;

/**
* MyEclipse Struts Creation date: 12-15-2008
*
* XDoclet definition:
*
* @struts.form name="roleForm"
*/
public class RoleForm extends BaseForm {
/*
* Generated Methods
*/

private SysRole role = new SysRole();

private String[] rights; // 选中的权限代码

public String[] getRights() {
return rights;
}

public void setRights(String[] rights) {
this.rights = rights;
}

public SysRole getRole() {
return role;
}

public void setRole(SysRole role) {
this.role = role;
}

/**
* Method validate
*
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
return null;
}

/**
* Method reset
*
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
role = new SysRole();
}
}


action:
public ActionForward doAdd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RoleForm roleForm = (RoleForm) form;
SysRole role = roleForm.getRole();
boolean bl = roleBiz.checkRoleName(role.getRoleName());
if (bl) {
request.setAttribute("operMessage", "角色已经存在!");
} else {
roleBiz.saveRole(role);
request.setAttribute("operMessage", "新建角色成功!");
}
roleForm.reset(mapping, request);
request.setAttribute("roleList", roleBiz.getRoleByPagination(roleForm
.getRole(), roleForm.getBean()));
return mapping.findForward("list");
}


热点排行