系统主页功能的实现
main.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
left.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
top.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
欢迎使用个人信息管理平台
toop.jsp
<%@page import="JavaBean.UserNameBean"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
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();
}
}
%>
个人信息管理
通讯录管理
日程安排管理
个人文件管理
退出主页面
欢迎<%=loginname%>使用本系统!
显示效果:
这里使用了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" %>
修改个人信息
修改个人密码
<%
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);
%>
<%=mess.getName()%>
<%=mess.getSex()%>
<%=mess.getBirth()%>
<%=mess.getNation()%>
<%=mess.getEdu()%>
<%=mess.getWork()%>
<%=mess.getPhone()%>
<%=mess.getPlace()%>
<%=mess.getEmail()%>
<%
}
}
%>
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" %>
查看个人信息
修改个人密码
<%
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);
%>
<%
}
}
%>
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" %>
修改个人信息
查看个人信息
<%
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);
%>
<%
}
}
%>
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;
}
}
项目源码