Welcome 布拉格

BlogJava 首页 联系 聚合 管理
  6 Posts :: 13 Stories :: 15 Comments :: 0 Trackbacks

(1)createUser!input.jsp

<FORM id="form1" METHOD=POST ACTION="createUserAction.jsp" onSubmit="return check();">
 <TABLE  class="inputTable">
  <TR><Th>用户名</Th><TD><INPUT TYPE="text" NAME="username" id="username"><span class="require">(*)</span></TD></TR>
  <TR><Th>密码</Th><TD><INPUT TYPE="password" NAME="password" id="password"><span class="require">(*)</span></TD></TR>
  <TR><Th>重输密码</Th><TD><INPUT TYPE="password" NAME="repwd" id="repwd"><span class="require">(*)</span></TD></TR>
  <TR><Th>&nbsp;</Th><TD><INPUT TYPE="submit" value="创建新用户"></TD></TR>
 </TABLE>
</FORM>

(2)

createUserAction.jsp

<sql:query var="rs" dataSource="${dataSource}" >
 select * from tb_user where username=?
 <sql:param value="${param['username']}"/>
</sql:query>

<c:choose>
<c:when test="${rs.rowCount==0}">
 <sql:update var="rs" dataSource="${dataSource}" >
  insert into tb_user(username,password) values(?,?)
  <sql:param value="${param['username']}"/>
  <sql:param value="${param['password']}"/>
 </sql:update>
 
 <c:redirect url="listUser.jsp"/>
</c:when>

<c:otherwise>
 <SCRIPT LANGUAGE="JavaScript">
 <!--
  alert("该用户名已存在");
  history.go(-1);
 //-->
 </SCRIPT>
</c:otherwise>
</c:choose>


(3)

editUser!input.jsp

<sql:query var="rs" dataSource="${dataSource}" >
   select * from tb_user where id = ?
   <sql:param value="${param['id']}"/>
  </sql:query>

  <c:set var="user" value="${rs.rows[0]}"/>

  <FORM METHOD=POST ACTION="editUserAction.jsp" onSubmit="return check();">
  <INPUT TYPE="hidden" NAME="id" value="${user.id}">
   <TABLE class="inputTable">
    <TR><Th>用户名</Th>
    <TD><INPUT TYPE="text" NAME="username" id="username" value="${user.username}"><span class="require"> (*必填)</span></TD></TR>
    <TR><Th>旧密码</Th><TD><INPUT TYPE="password" NAME="oldPassword"  id="oldPassword" ><span class="require"> (*必填)</span></TD></TR>
    <TR><Th>新密码</Th><TD><INPUT TYPE="password" NAME="password"  id="password"><span class="require"> (*必填)</span></TD></TR>
    <TR><Th>重输新密码</Th><TD><INPUT TYPE="password" NAME="repwd" id="repwd"><span class="require"> (*两次密码必须相同)</span></font></TD></TR>
    <TR><Th>&nbsp;&nbsp;&nbsp;&nbsp;</Th><TD><INPUT TYPE="submit" value="编辑"></TD></TR>
   </TABLE>
  </FORM>

(4)

editUserAction.jsp

<sql:query var="rs" dataSource="${dataSource}" >
 select password from tb_user where id = ?
 <sql:param value="${param['id']}"/>
</sql:query>

<c:choose>
<c:when test="${rs.rows[0].password!=param['oldPassword']}">
 <SCRIPT LANGUAGE="JavaScript">
 <!--
  alert("旧密码错误!");
  history.go(-1);
 //-->
 </SCRIPT>
</c:when>

<c:otherwise>
 <sql:query var="rs" dataSource="${dataSource}" >
  select * from tb_user where id <> ? and username = ?             ??  <>  不等于
  <sql:param value="${param['id']}"/>
  <sql:param value="${param['username']}"/>
 </sql:query>
 
 <c:choose>
 <c:when test="${rs.rowCount==0}">
  <sql:update var="rs" dataSource="${dataSource}" >
   update tb_user set username = ?,password = ? where id = ?
   <sql:param value="${param['username']}"/>
   <sql:param value="${param['password']}"/>
   <sql:param value="${param['id']}"/>
  </sql:update>
  
  <c:redirect url="listUser.jsp"/>
 </c:when>
 
 <c:otherwise>
  <SCRIPT LANGUAGE="JavaScript">
  <!--
   alert("该用户名已存在");
   history.go(-1);
  //-->
  </SCRIPT>
 </c:otherwise>
 </c:choose>

</c:otherwise>
</c:choose>

(5)
deleteUserAction.jsp

<sql:update var="rs" dataSource="${dataSource}" >
  delete from tb_user  where id = ?
  <sql:param value="${param['id']}"/>
</sql:update>
 
<c:redirect url="listUser.jsp"/>

posted on 2007-09-13 11:14 Welcome 阅读(345) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: