基于struts2的个人信息管理系统(三)

该博客介绍了基于Struts2框架实现的个人信息管理系统,包括系统主页的展示,如main.jsp、left.jsp、top.jsp等页面,以及个人信息的查看、修改和个人密码修改等功能。在个人信息管理中,详细阐述了lookMessage.jsp、updateMessage.jsp和updatePass.jsp的代码实现及对应的业务控制器。
摘要由CSDN通过智能技术生成

系统主页功能的实现

main.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="个人信息管理系统"/></title>
    </head>
    <frameset cols="20%,*" framespacing="0" border="no" frameborder="0">
        <frame src="../mainFrame/left.jsp" name="left" scrolling="no">
        <frameset rows="20%,10%,*">
            <frame src="../mainFrame/top.jsp" name="top" scrolling="no">
            <frame src="../mainFrame/toop.jsp" name="toop" scrolling="no">
            <frame src="../mainFrame/about.jsp" name="main">
        </frameset>
    </frameset>

</html>

left.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="个人管理系统"/></title>
    </head>
    <body bgcolor="#CCCCFF">
        <table>
            <tr>
                <td>
                    <img src="../images/2.jpg" width="100%" height="100%">
                </td>
            </tr>
        </table>
    </body>
</html>

top.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="个人管理系统"/></title>
    </head>
    <body bgcolor="#CCCCFF">
        <table width="100%" align="center">
          <tr  align="center">
              <td align="right">
                  <img src="../images/1.jpg" height="100">
              </td>
              <td align="left">
                  <h1><font color="blue">欢迎使用个人信息管理平台</font></h1>
              </td>
          </tr>
      </table>
    </body>
</html>

toop.jsp

<%@page import="JavaBean.UserNameBean"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="个人管理系统"/></title>
    </head>
    <body bgcolor="#CCDDEE">
        <%  
            String loginname=null;
            ArrayList login=(ArrayList)session.getAttribute("userName");
            if(login==null||login.size()==0){
                loginname="水木清华";
            }else{
                for(int i=login.size()-1;i>=0;i--){
                    UserNameBean nm=(UserNameBean)login.get(i);
                    loginname=nm.getUserName();
                }
            }
        %>
        <table width="100%" align="right" bgcolor="blue">
              <tr height="10" bgcolor="gray" align="center">
                  <td><a href="http://localhost:8080/ch13/personMessage/lookMessage.jsp" target="main">个人信息管理</a></td>
                  <td><a href="http://localhost:8080/ch13/friendManager/lookFriends.jsp" target="main">通讯录管理</a></td>
                  <td><a href="http://localhost:8080/ch13/dateTimeManager/lookDay.jsp" target="main">日程安排管理</a></td>
                  <td><a href="http://localhost:8080/ch13/fileManager/lookFile.jsp" target="main">个人文件管理</a></td>
                  <td><a href="http://localhost:8080/ch13/login/index.jsp" target="_top">退出主页面</a></td>
                  <td>欢迎<%=loginname%>使用本系统!</td>
              </tr>
        </table>
    </body>
</html>

显示效果:


这里使用了frame框架,具体的可以自己去了解。

个人信息管理功能的实现

查看个人信息:


修改个人信息


修改个人密码


具体的代码实现

lookMessage.jsp

<%@page import="JavaBean.MyMessBean"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="个人信息管理系统"></s:text></title>
    </head>
    <body bgcolor="gray">
      <hr noshade/>
      <s:div align="center">
      <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
          <tr>
              <td width="33%">
                  <s:a href="http://localhost:8080/ch13/personMessage/updateMessage.jsp">修改个人信息</s:a>
              </td>
              <td width="33%">
                  <s:text name="查看个人信息"></s:text>
              </td>
              <td width="33%">
                  <s:a href="http://localhost:8080/ch13/personMessage/updatePass.jsp">修改个人密码</s:a>
              </td>
          </tr>
      </table>
      </s:div>
      <hr noshade/>
      <table border="5" cellspacing="0" cellpadding="0" bgcolor="#95BDFF" width="60%" align="center">
          <%
            ArrayList MyMessage=(ArrayList)session.getAttribute("MyMess");
            if(MyMessage==null||MyMessage.size()==0){
                response.sendRedirect("http://localhost:8080/ch13/login/index.jsp");
            }else{
                for(int i=MyMessage.size()-1;i>=0;i--){
                    MyMessBean mess=(MyMessBean)MyMessage.get(i);
                    %>
                       <tr>
                         <td height="30"><s:text name="用户姓名"></s:text></td>
                         <td><%=mess.getName()%></td>
                       </tr>
                       <tr>
                         <td height="30"><s:text name="用户性别"></s:text></td>
                         <td><%=mess.getSex()%></td>
                       </tr>
                       <tr>
                         <td height="30"><s:text name="出生日期"></s:text></td>
                         <td><%=mess.getBirth()%></td>
                       </tr>
                       <tr>
                         <td height="30"><s:text name="用户民族"></s:text></td>
                         <td><%=mess.getNation()%></td>
                       </tr>
                       <tr>
                         <td height="30"><s:text name="用户学历"></s:text></td>
                         <td><%=mess.getEdu()%></td>
                       </tr>
                       <tr>
                         <td height="30"><s:text name="用户职称"></s:text></td>
                         <td><%=mess.getWork()%></td>
                       </tr>
                       <tr>
                         <td height="30"><s:text name="用户电话"></s:text></td>
                         <td><%=mess.getPhone()%></td>
                       </tr>
                       <tr>
                         <td height="30"><s:text name="家庭住址"></s:text></td>
                         <td><%=mess.getPlace()%></td>
                       </tr>
                       <tr>
                           <td height="30"><s:text name="邮箱地址"></s:text></td>
                         <td><%=mess.getEmail()%></td>
                       </tr>
                    <%
                }
            }
          %>
        </table>
    </body>
</html>

lookMessage.jsp使用MyMessBean类保存数据

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JavaBean;

public class MyMessBean {
    private String name;
    private String sex;
    private String birth;
    private String nation;
    private String edu;
    private String work;
    private String phone;
    private String place;
    private String email;
    public MyMessBean(){
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getBirth() {
        return birth;
    }
    public void setBirth(String birth) {
        this.birth = birth;
    }
    public String getNation() {
        return nation;
    }
    public void setNation(String nation) {
        this.nation = nation;
    }
    public String getEdu() {
        return edu;
    }
    public void setEdu(String edu) {
        this.edu = edu;
    }
    public String getWork() {
        return work;
    }
    public void setWork(String work) {
        this.work = work;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getPlace() {
        return place;
    }
    public void setPlace(String place) {
        this.place = place;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
}

updateMessage.jsp

<%@page import="JavaBean.MyMessBean"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="个人信息管理系统->修改信息"></s:text></title>
    </head>
    <body bgcolor="gray">
        <hr noshade/>
      <s:div align="center">
      <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
          <tr>
              <td width="33%">
                  <s:text name="修改个人信息"></s:text>
              </td>
              <td width="33%">
                  <s:a href="http://localhost:8080/ch13/personMessage/lookMessage.jsp">查看个人信息</s:a>
              </td>
              <td width="33%">
                  <s:a href="http://localhost:8080/ch13/personMessage/updatePass.jsp">修改个人密码</s:a>
              </td>
          </tr>
      </table>
      </s:div>
      <hr noshade/>
      <s:form action="upMessAction" method="post">
      <table border="5" cellspacing="0" cellpadding="0" bgcolor="#95BDFF" width="60%" align="center">
          <%
            ArrayList MyMessage=(ArrayList)session.getAttribute("MyMess");
            if(MyMessage==null||MyMessage.size()==0){
                response.sendRedirect("http://localhost:8080/ch13/login/index.jsp");
            }else{
                for(int i=MyMessage.size()-1;i>=0;i--){
                    MyMessBean mess=(MyMessBean)MyMessage.get(i);
                    %>
                       <tr>
                            <td height="30"><s:text name="用户姓名"></s:text></td>
                            <td><input type="text" name="name" value="<%=mess.getName()%>"/></td>
                       </tr>
                       <tr>
                            <td height="30"><s:text name="用户性别"></s:text></td>
                            <td><input type="text" name="sex" value="<%=mess.getSex()%>"/></td>
                       </tr>
                       <tr>
                            <td height="30"><s:text name="出生日期"></s:text></td>
                            <td><input type="text" name="birth" value="<%=mess.getBirth()%>"/></td>
                       </tr>
                       <tr>
                            <td height="30"><s:text name="用户民族"></s:text></td>
                            <td><input type="text" name="nation" value="<%=mess.getNation()%>"/></td>
                       </tr>
                       <tr>
                            <td height="30"><s:text name="用户学历"></s:text></td>
                            <td><input type="text" name="edu" value="<%=mess.getEdu()%>"/></td>
                       </tr>
                       <tr>
                            <td height="30"><s:text name="用户职称"></s:text></td>
                            <td><input type="text" name="work" value="<%=mess.getWork()%>"/></td>
                       </tr>
                       <tr>
                            <td height="30"><s:text name="用户电话"></s:text></td>
                            <td><input type="text" name="phone" value="<%=mess.getPhone()%>"/></td>
                       </tr>
                       <tr>
                            <td height="30"><s:text name="家庭住址"></s:text></td>
                            <td><input type="text" name="place" value="<%=mess.getPlace()%>"/></td>
                       </tr>
                       <tr>
                            <td height="30"><s:text name="邮箱地址"></s:text></td>
                            <td><input type="text" name="email" value="<%=mess.getEmail()%>"/></td>
                       </tr>
                       <tr>
                            <td colspan="2" align="center">
                             <input type="submit" value="确 定"/>
                                   
                             <input type="reset" value="还 原"/>
                            </td>
                       </tr>
                    <%
                }
            }
          %>
        </table>
      </s:form>
    </body>
</html>

updateMessage.jsp对应的业务控制器类为UpdateMessAction

package edu.personManager.Action;

import DBJavaBean.DB;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
//import javax.swing.JOptionPane;
import org.apache.struts2.interceptor.ServletRequestAware;

public class UpdateMessAction extends ActionSupport implements ServletRequestAware {
    private String name;
    private String sex;
    private String birth;
    private String nation;
    private String edu;
    private String work;
    private String phone;
    private String place;
    private String email;
    private String userName;
    private HttpServletRequest request;
    private String message=ERROR;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getBirth() {
        return birth;
    }
    public void setBirth(String birth) {
        this.birth = birth;
    }
    public String getNation() {
        return nation;
    }
    public void setNation(String nation) {
        this.nation = nation;
    }
    public String getEdu() {
        return edu;
    }
    public void setEdu(String edu) {
        this.edu = edu;
    }
    public String getWork() {
        return work;
    }
    public void setWork(String work) {
        this.work = work;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getPlace() {
        return place;
    }
    public void setPlace(String place) {
        this.place = place;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public void setServletRequest(HttpServletRequest hsr) {
        request=hsr;
    }
//    public void message(String msg){
//        int type=JOptionPane.YES_NO_OPTION;
//        String title="信息提示";
//        JOptionPane.showMessageDialog(null,msg,title,type);
//    }
    @Override
    public void validate(){
        if(getName()==null||getName().length()==0){
            addFieldError("name","用户姓名不允许为空!");
        }
        if(getSex()==null||getSex().length()==0){
            addFieldError("sex","用户性别不允许为空!");
        }
//         if(!(getSex().equals("男"))||!(getSex().equals("女"))){
//            addFieldError("sex","用户性别符合标准!");
//        }
        if(getBirth()==null||getBirth().length()==0){
            addFieldError("birth","用户生日不允许为空!");
        }else{
            if(getBirth().length()!=10){
                addFieldError("birth","用户生日格式为'yyyy-mm-dd'!");
            }else{
                String an=this.getBirth().substring(4, 5);
                String bn=this.getBirth().substring(7, 8);
                if(!(an.equals("-"))||!(bn.equals("-"))){
                    addFieldError("birth","用户生日格式为'yyyy-mm-dd'!");
                }
            }
        }
        if(getNation()==null||getNation().length()==0){
            addFieldError("nation","用户民族不允许为空!");
        }
        if(getEdu()==null||getEdu().length()==0){
            addFieldError("edu","用户学历不允许为空!");
        }
        if(getWork()==null||getWork().length()==0){
            addFieldError("work","用户工作不允许为空!");
        }
        if(getPhone()==null||getPhone().length()==0){
            addFieldError("phone","用户电话不允许为空!");
        }
        if(getPlace()==null||getPlace().length()==0){
            addFieldError("place","用户地址不允许为空!");
        }
        if(getEmail()==null||getEmail().length()==0){
            addFieldError("email","用户email不允许为空!");
        }
    }
    public String execute() throws Exception {
        DB mysql=new DB();
        System.out.println(this.getName()+this.getSex()+this.getBirth()+this.getNation()+this.getEdu()+this.getWork()+this.getPhone()+this.getPlace()+this.getEmail());
        userName=mysql.returnLogin(request);
        String mess=mysql.updateMess(request, userName, this.getName(), this.getSex(), this.getBirth(), this.getNation(), this.getEdu(), this.getWork(), this.getPhone(), this.getPlace(), this.getEmail());
        if(mess.equals("ok")){
            message=SUCCESS;
        }
        return message;
    }  
}

updatePass.jsp

<%@page import="java.util.ArrayList"%>
<%@page import="JavaBean.UserNameBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="个人信息管理系统->修改密码"></s:text></title>
    </head>
    <body bgcolor="gray">
      <hr noshade/>
      <s:div align="center">
      <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
          <tr>
              <td width="33%">
                  <s:a href="http://localhost:8080/ch13/personMessage/updateMessage.jsp">修改个人信息</s:a>
              </td>
              <td width="33%">
                  <s:a href="http://localhost:8080/ch13/personMessage/lookMessage.jsp">查看个人信息</s:a>
              </td>
              <td width="33%">
                  <s:text name="修改个人密码"></s:text>
              </td>
          </tr>
      </table>
      </s:div>
      <hr noshade/>
      <s:form action="upPassAction" method="post">
      <table border="5" cellspacing="0" cellpadding="0" bgcolor="#95BDFF" width="60%" align="center">
          <%
            ArrayList login=(ArrayList)session.getAttribute("userName");
            if(login==null||login.size()==0){
                response.sendRedirect("http://localhost:8080/ch13/login/index.jsp");
            }else{
                for(int i=login.size()-1;i>=0;i--){
                    UserNameBean nm=(UserNameBean)login.get(i);
                    %>
                       <tr>
                           <td height="30"><s:text name="用户密码"></s:text></td>
                         <td><input type="text" name="password1" value="<%=nm.getPassword()%>"/></td>
                       </tr>
                       <tr>
                         <td height="30"><s:text name="重复密码"></s:text></td>
                         <td><input type="text" name="password2" value="<%=nm.getPassword()%>"/></td>
                       </tr>
                       <tr>
                         <td colspan="2" align="center">
                             <input type="submit" value="确 定" size="12"/>
                                   
                             <input type="reset" value="清 除" size="12"/>
                         </td>
                       </tr>
                    <%
                    }
            }
          %>
        </table>
       </s:form>
    </body>
</html>

update对应的业务控制器类为UpdatePassAction

package edu.personManager.Action;

import DBJavaBean.DB;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import javax.swing.JOptionPane;
import org.apache.struts2.interceptor.ServletRequestAware;

public class UpdatePassAction extends ActionSupport implements ServletRequestAware{
    private String password1;
    private String password2;
    private String userName;
    private HttpServletRequest request;
    private String message=ERROR;
    public String getPassword1() {
        return password1;
    }
    public void setPassword1(String password1) {
        this.password1 = password1;
    }
    public String getPassword2() {
        return password2;
    }
    public void setPassword2(String password2) {
        this.password2 = password2;
    }
    public void setServletRequest(HttpServletRequest hsr) {
        request=hsr;
    }
    public void message(String msg){
        int type=JOptionPane.YES_NO_OPTION;
        String title="信息提示";
        JOptionPane.showMessageDialog(null,msg,title,type);
    }
    public void validate(){
        if(!(password1.equals(password2))){
            message("两次密码不同!");
            addFieldError("password2","两次密码不同!");
        }
    }
    public String execute() throws Exception {
        DB mysql=new DB();
        userName=mysql.returnLogin(request);
        String pass=mysql.updatePass(request, userName, this.getPassword1());
        if(pass.equals("ok")){
            message=SUCCESS;
        }
        return message;
    } 
}
项目源码
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值