通俗易懂的讲解SSH2+JS实现重命名的判断

本博客讲述如何利用js+ssh2实现重命名的判断,希望读者看完了博客能够将这个简单的小功能实现了。

首先建立一个添加系统的一个页面:

<%@ page contentType="text/html;charset=utf-8" language="java"
   import="java.sql.*" errorPage=""%>
<%
   Stringpath = request.getContextPath();
   StringbasePath = request.getScheme() + "://"
         +request.getServerName() + ":" + request.getServerPort()
         +path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type"content="text/html; charset=utf-8" />
<title>权限管理</title>
<link href="<%=basePath%>css/basePage.css"rel="stylesheet"
   type="text/css" />
 
 
<link href="<%=basePath%>css/baseStyle.css"rel="stylesheet"
   type="text/css" />
<link rel="stylesheet"type="text/css"
   href="<%=basePath%>css/addccStyle.css" />
<script src="<%=basePath%>/js/client_validate.js"type="text/javascript"></script>
 
<script language="javascript"type="text/javascript">
   function menu_click(page){
      window.self.location= '<%=basePath%>' + page;
   }
   function _addbtn(){
      var systemName =document.getElementById("systemName");
        if (trim(systemName.value) == "") {
         alert("系统名称名称不能为空!");
         systemName.focus();
         return;
      }
      var myForm =document.forms[0];
      myForm.action= "webSystemManager!addWebSystem";
      myForm.submit();  
   }
   function _goback(){
      window.self.location= "<%=basePath%>permission/sysmgr/system_add.jsp";
   }
  
   function init() {
      var systemName =document.getElementById("systemName");
      var s = '<%=request.getAttribute("system_isExist")%>';
 
      if(s == "1"){
         alert("该系统已经存在!");
         systemName.focus();
         systemName.value="";
         return;
      }
     
      var res = "<%=request.getAttribute("addRes")%>";
      if(res == 1){
         alert("添加成功!");
         systemName.focus();
         systemName.value="";
         return;
      }
      systemName.focus();
   } 
  
</script>
</head>
<body menu='menu' onload="init()">
   <div class="header">
      <div class="header03"></div>
      <div class="header01"></div>
      <div class="header02">权限管理系统</div>
   </div>
   <div class="left" id="LeftBox">
      <div class="left01">
         <div class="left01_right"></div>
         <div class="left01_left"></div>
         <div class="left01_c">超级管理员:admin</div>
      </div>
      <div class="left02">
         <div class="left02top">
            <div class="left02top_right"></div>
            <div class="left02top_left"></div>
            <div class="left02top_c">基本信息维护</div>
         </div>
         <div class="left02down">
            <div class="left02down01"
                onclick="menu_click('permission/usermgr/role_maint.jsp')">角色管理</div>
            <div class="left02down01"
                onclick="menu_click('permission/usermgr/group_maint.jsp')">用户组管理</div>
            <div class="left02down01"
                onclick="menu_click('permission/usermgr/user_maint.jsp')">用户管理</div>
         </div>
         <div class="left02top">
            <div class="left02top_right"></div>
            <div class="left02top_left"></div>
            <div class="left02top_c">授权维护</div>
         </div>
         <div class="left02down">
            <div class="left02down01"
               onclick="menu_click('permission/authoriedmgr/role_authoried_maint.jsp')">角色权限管理</div>
            <div class="left02down01"
               onclick="menu_click('permission/authoriedmgr/group_authoried_maint.jsp')">用户组权限管理</div>
            <div class="left02down01"
               onclick="menu_click('permission/authoriedmgr/user_authoried_maint.jsp')">用户权限管理</div>
         </div>
         <div class="left02top">
            <div class="left02top_right"></div>
            <div class="left02top_left"></div>
            <div class="left02top_c">系统维护</div>
         </div>
        
         <div class="left02down" id="leftlast">
            <div class="left02down01"
                onclick="menu_click('webSystemManager!getWebSystemByQueryString?pageNo=1&queryString=null')">系统管理</div>
            <div class="left02down01"
                onclick="menu_click('webPageManager!getWebPageByQueryString?pageNo=1&queryString=null')">页面管理</div>
            <div class="left02down01"
                onclick="menu_click('moduleManager!getModuleByQueryString?pageNo=1&queryString=null')">模块管理</div>
            <div class="left02down01"
                onclick="menu_click('operateManager!getOperateByQueryString?pageNo=1&queryString=null')">操作管理</div>
         </div>
         <div class="left03 left02top">
            <div class="left03_right"></div>
            <div class="left01_left"></div>
            <div class="left03_c">安全退出</div>
         </div>
      </div>
   </div>
   <form id="addsystemform" method="post">
      <div id="RightBox">
         <div id="permission_header">
            <div id="permission_guid">系统维护>>添加系统</div>
 
            <div id="split_line">
                <hr />
            </div>
         </div>
         <div id="operation_main">
            <div id="select_guid">添加系统</div>
            <div id="prompt_select">
                <span id="span_prompt">第二步(共两步):</span>添加系统信息
            </div>
            <div id="select_mothed">
                <div class="guid_cc">
                   系统名称:<input type="text"  id="systemName"  name="webSystem.name"/>
                </div>
            </div>
            <div id="btn_next">
                <input type="button" class="operation_btn"name="btnReturn"
                   id="btnReturn" value="返回" onclick="_goback()" /> <input
                   type="button" class="operation_btn"name="btnAdd" id="btnAdd"
                   value="添加" onclick="_addbtn()" />
 
            </div>
         </div>
         <div id="permission_footer">
            <div id="inner_footer">
                <p class="copyright">Copyright © 2012 信息技术提高班.</p>
            </div>
         </div>
      </div>
   </form>
</body>
</html>
 


之后建立相应的Action:

public classWebSystemManagerAction extends ActionSupport {
  
   private WebSystem webSystem;
  
   @Resource
   privateIWebSystemManager<Long> webSystemManager;
  
  
   private HttpServletRequest request;
  
   private StringBuffer sbTreeHTML = new StringBuffer();
  
  
   public WebSystemgetWebSystem() {
      return webSystem;
   }
  
   public void setWebSystem(WebSystemwebSystem) {
      this.webSystem = webSystem;
   }
  
   /**
    * 添加系统信息
    * @return
    * @throws Exception
    */
   public String addWebSystem() throws Exception {
      //先查找是否存在
      int res = 0;
      res= webSystemManager.getWebSystemNameIsExist(webSystem.getName());
      request = ServletActionContext.getRequest();
      //若存在,group_isExist为1,若不存在group_isExist为0
      request.setAttribute("system_isExist","0");
      request.setAttribute("addRes",0);
 
      if(res > 0){      
         request.setAttribute("system_isExist","1");
      }else{
         webSystemManager.saveWebSystem(webSystem);
         request.setAttribute("addRes",1);
      }
      return "webSystemAdd";
   }


bll层代码(这里仅仅写实现了):

@Override
   public intgetWebSystemNameIsExist(String webSystemName) {
      int res = 0;
      WebSystemwebSystem = webSystemDao.findWebSystemByName(webSystemName);
      if(!BeanUtil.isNull(webSystem)){
         res= 1;
      }
      return res;
   }


Dao层代码(这里也仅仅写实现):

@Override
   public WebSystemfindWebSystemByName(String webSystemName) {
      baseDao.clearBaseDao(baseDao);
      baseDao.setEntityClass(WebSystem.class);
      Stringhql = "from WebSystem a where a.name=?";
      IQueryquery = baseDao.createQuery();
      query.setQueryString(hql);
      query.setParamValues(new Object[]{webSystemName});
      WebSystemwebSystem=null;
      if(baseDao.find(query).size()>0 ){
         webSystem= (WebSystem)baseDao.find(query).get(0);
      }
      return webSystem;
   }
 


之后配置相关信息:

Bll层配置:

<bean id="webSystemManager"
class="com.core.permission.impl.WebSystemManagerImpl"></bean>


Dao层配置:

<bean id="webSystemDao"
 class="com.core.permission.dao.impl.WebSystemDaoImpl"></bean>


Action配置:

<beanname="webSystemManagerAction"
class="com.web.action.WebSystemManagerAction"scope="prototype"></bean>

最后就是struts2的相关配置:

<action name="webSystemManager"  class="webSystemManagerAction">
         <result name="webSystemAdd">/permission/sysmgr/system_add_addsystem.jsp</result>
      </action>


运行结果:

1:

通俗易懂的讲解SSH2+JS实现重命名的判断_第1张图片

2:

通俗易懂的讲解SSH2+JS实现重命名的判断_第2张图片

3:

通俗易懂的讲解SSH2+JS实现重命名的判断_第3张图片


通过这个小实例,相信大家一定会利用js+ssh2实现重命名的判断了,其实懂了这个其他的判断都会非常简单。其实最主要还是在那个init方法上,细心的读者会发现那个init方法的妙处。

你可能感兴趣的:(ssh2)