这次真的废了好大劲,不是这里落下了一个组件就是那里路径又写错了,趁现在能运行赶紧记录一下。
(现在由于插入功能还不能实现,所以注册功能实现不了,应该是hql语句的问题,到时候有空的时候好好琢磨以下UserDao里继承insert函数)
添加组件,这里包含了struts2,Hibernate,数据库连接,c3p0,excel导出和opensymphony.xwork2的组件,如下
组件链接
首先,建立工程的时候要记得建web.xml,要是忘记建立了可以在工程文件上单击右键,选择javaeeTools中的Generate Deployment选项建立,内容中包含struts2的相关信息
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Struts Blank002</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我刚开始就忘记配置这个了,一直显示无监听,找了好久的原因才找到。
然后配置Hibernate
src下的Hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/javaee?useSSL=false&serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.provider_class">
org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.max_size">5</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- 格式化SQL -->
<property name="hibernate.format_sql">true</property>
<!--指定关联的 。hbm。xml文件 -->
<mapping resource="com/edu/model/user/User.hbm.xml"></mapping>
<mapping resource="com/edu/model/card/Card.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
src下HibernateUtil类
package com.edu.db_util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public final class HibernateUtil {
private static SessionFactory sessionFactory;
private static ThreadLocal session =new ThreadLocal();
private HibernateUtil(){}
static{
Configuration configuration=new Configuration().configure();
StandardServiceRegistryBuilder regbuilder=new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry=regbuilder.build();
sessionFactory=configuration.buildSessionFactory(serviceRegistry);
}
public static Session getThreadLocalSession(){//获取session对象的方法
Session s=(Session)session.get();
if(s==null){
s=sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void clossSession(){
Session s=(Session)session.get();
if(s!=null){s.close();session.set(null);}
}
}
Action配置
UserAction.java
package com.edu.action.user;
import com.edu.dao.user.UserDao;
import com.edu.model.user.User;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private User user;
private String re_password;
private String msg;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getRe_password() {
return re_password;
}
public void setRe_password(String re_password) {
this.re_password = re_password;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
private UserDao userDao=new UserDao();
public String userLogin() {
String forward = null;
User endUser = userDao.findBynameAndPassword(user);
if (endUser != null) {
forward = "success";
user.setUserRealName(endUser.getUserRealName());
} else {
msg="用户不存在或密码不正确,登录失败,请重新登录或注册!";
forward = "failure";
}
return forward;
}
public String userRegister(){
String forward;
int flag;
User endUser=userDao.fingByname(user);
if(endUser!=null&&(endUser.getUserName().trim().equals(user.getUserName().trim()))){
msg = "该用户已经存在,请重新注册!";
forward="error";
}else{
flag = userDao.insert(user);
if (flag==1){
forward="success";
}else{
msg="数据库写错误";
forward="error";
}
}
return forward;
}
}
用户注册验证信息配置
UserAction-register-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<validators>
<field name="user.userName">
<field-validator type="requiredstring" short-circuit="true">
<param name="trim">true</param>
<message>User name cannot be empty!</message>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[^[a-zA-Z]\w*$]]></param>
<message>Incorrect user name format!</message>
</field-validator>
</field>
<field name="user.userPassword">
<field-validator type="requiredstring" short-circuit="true">
<param name="trim">true</param>
<message>Password cannot be empty!</message>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">6</param>
<message>Password length cannot be less than 6!</message>
</field-validator>
</field>
<field name="user.userPassword">
<field-validator type="requiredstring" short-circuit="true">
<message>Confirm password cannot be empty!</message>
</field-validator>
<field-validator type="fieldexpression">
<param name="expression"><![CDATA[re_password==user.userPassword]]></param>
<message>The two passwords are inconsistent!</message>
</field-validator>
</field>
</validators>
CardAction.java
package com.edu.action.card;
import com.edu.dao.card.CardDao;
import com.edu.model.card.Card;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.inject.Scope;
import com.opensymphony.xwork2.inject.Scoped;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import javax.servlet.Servlet;
import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.List;
@Namespace("/card")
@Scoped(Scope.REQUEST)
@ParentPackage("struts-default")
public class CardAction extends ActionSupport {
private CardDao cardDao=new CardDao();
private Card card;
private String condition;
private String[] checkList;
private int id;
private String order;
private long pageNo;
private int pageSize;
private long recordCount;
private long pageCount;
private List<Card>listCard;
private String msg;
private HttpSession session;
public CardDao getCardDao() {
return cardDao;
}
public void setCardDao(CardDao cardDao) {
this.cardDao = cardDao;
}
public Card getCard() {
return card;
}
public void setCard(Card card) {
this.card = card;
}
public String getCondition() {
return condition;
}
public void setCondition(String condition) {
this.condition = condition;
}
public String[] getCheckList() {
return checkList;
}
public void setCheckList(String[] checkList) {
this.checkList = checkList;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
public long getPageNo() {
return pageNo;
}
public void setPageNo(long pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public long getRecordCount() {
return recordCount;
}
public void setRecordCount(long recordCount) {
this.recordCount = recordCount;
}
public long getPageCount() {
return pageCount;
}
public void setPageCount(long pageCount) {
this.pageCount = pageCount;
}
public List<Card> getListCard() {
return listCard;
}
public void setListCard(List<Card> listCard) {
this.listCard = listCard;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public HttpSession getSession() {
return session;
}
public void setSession(HttpSession session) {
this.session = session;
}
@Action(
value="insert",
results = {
@Result(name="success",location = "/find",type="redirectAction")
}
)
public String insert(){
cardDao.insert(card);
msg="插入一条记录成功!";
return "success";
}
@Action(
value="insertList",
results = {@Result(name="success",location = "/find",type="redirectAction")}
)
public String insertList(){
int n=cardDao.insertList(listCard);
msg="插入一组("+n+")记录成功!";
return "success";
}
@Action(
value="delete",
results = {@Result(name="success",location = "/find",type="redirectAction")}
)
public String delete(){
cardDao.delete(id);
msg="删除一条记录成功!";
return "success";
}
@Action(
value="deleteList",
results = {@Result(name="success",location = "/find",type="redirectAction")}
)
public String deleteList(){
int ids[]=new int[checkList.length];
for(int i=0;i<checkList.length;i++){
ids[i]=Integer.parseInt(checkList[i]);
}
int n=cardDao.deleteList(ids);
msg="删除一组(+"+n+")记录成功!";
return "success";
}
@Action(
value="find",
results = {@Result(name="success",location = "/list.jsp",type="dispatcher")}
)
public String find(){
listCard=cardDao.findByCondition(condition,"0");
session = ServletActionContext.getRequest().getSession();
session.setAttribute("condition",condition);
session.setAttribute("order",order);
return "success";
}
@Action(
value="findupdate",
results = {@Result(name="success",location = "/update.jsp",type="dispatcher")}
)
public String findUpdate(){
card = cardDao.findById(id,"0");
return "success";
}
@Action(
value="retrieve",
results = {@Result(name="success",location = "/find",type="redirectAction")}
)
public String retrieve() throws SQLException {
int ids[]=new int[checkList.length];
for(int i=0;i<checkList.length;i++){
ids[i]=Integer.parseInt(checkList[i]);
}
cardDao.retrieve(ids);
return "success";
}
@Action(
value="update",
results = {@Result(name="success",location = "/find",type="redirectAction")}
)
public String update() {
cardDao.update(card);
return "success";
}
}
数据库操作接口IBaseDao.java
package com.edu.dao;
import java.util.List;
public interface IBaseDao<T> {
public int insert(T o);//将对象o添加到数据库内
public int insertList(List<T> list);//将对象集合添加到数据库内
public int update(T o);//利用对象o修改当前记录
public int deleteList(Class c,int...ids);//利用id的集合,删除该集合中对应id的记录
public int delete(T o);//从数据库中删除一个记录o
public int delete(Class c,int id);//利用关键字id从数据库中删除一条记录
public T findById(Class c,int id);//利用id查找一条记录
public T findOne(String hql,String []param);//查找单条记录
public List<T> find(String hql,String []param,int page,int size);//按条件查找多条记录
public List<T> findPage(String hql,String[] param,int page,int size);//分页查找所有对象
public int getCount(String hql,String[] param);//返回数据个数
public List<T> findByFields(String hql,String fields[],String condition);//单字段模糊查找
}
Hibernate操作数据库类
DaoHibernate.java
package com.edu.dao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.edu.db_util.HibernateUtil;
public class DaoHibernate<T> implements IBaseDao<T>{
@Override
public int insert(T o) {
// TODO Auto-generated method stub
Session s=null;
Transaction tx=null;
int result=0;
try{
s=HibernateUtil.getThreadLocalSession();
tx= s.beginTransaction();
s.save(o);
tx.commit();
result=1;
}catch(Exception e){if(tx!=null) {tx.rollback();}
}finally{HibernateUtil.clossSession();}
return result;
}
@Override
public int insertList(List<T> list) {
// TODO Auto-generated method stub
for(T t:list){
insert(t);
}
return list.size();
}
@Override
public int update(T o) {
// TODO Auto-generated method stub
Session s=null;
int result=0;
Transaction tx=null;
try{
s=HibernateUtil.getThreadLocalSession();
tx=s.beginTransaction();
s.update(o);
tx.commit();
result=1;
}catch(Exception e){if(tx!=null) {tx.rollback();}
}finally{HibernateUtil.clossSession();}
return result;
}
@Override
public int deleteList(Class c, int... ids) {
// TODO Auto-generated method stub
for(int id:ids){
delete(c,id);
}
return ids.length;
}
@Override
public int delete(T o) {
// TODO Auto-generated method stub
Session s=null;
int result=0;
Transaction tx=null;
try{
s=HibernateUtil.getThreadLocalSession();
tx=s.beginTransaction();
s.delete(o);
tx.commit();
result=1;
}catch(Exception e){if(tx!=null) {tx.rollback();}
}finally{HibernateUtil.clossSession();}
return result;
}
@Override
public int delete(Class c, int id) {
// TODO Auto-generated method stub
Session s=null;
int result=0;
Transaction tx=null;
try{
s=HibernateUtil.getThreadLocalSession();
tx=s.beginTransaction();
s.delete(s.load(c, id));
tx.commit();
result=1;
}catch(Exception e){if(tx!=null) {tx.rollback();}
}finally{HibernateUtil.clossSession();}
return result;
}
@Override
public T findById(Class c, int id) {
// TODO Auto-generated method stub
Session s=null;
T t=null;
try{
s=HibernateUtil.getThreadLocalSession();
t=(T)s.get(c, id);
}finally{HibernateUtil.clossSession();}
return t;
}
@Override
public T findOne(String hql, String[] param) {
// TODO Auto-generated method stub
Session s=null;
T t=null;
try{
s=HibernateUtil.getThreadLocalSession();
Query query=s.createQuery(hql);
if(param!=null){
for(int i=0;i<param.length;i++){
query.setParameter(i, param[i]);
}
}
t=(T)query.uniqueResult();
}finally{HibernateUtil.clossSession();}
return t;
}
@Override
public List<T> find(String hql, String[] param, int page, int size) {
// TODO Auto-generated method stub
Session s=null;
List<T> list=null;
try{
s=HibernateUtil.getThreadLocalSession();
Query query=s.createQuery(hql);
if(param!=null){
for(int i=0;i<param.length;i++){
query.setParameter(i, param[i]);
}
}
list=query.list();
}finally{HibernateUtil.clossSession();}
return list;
}
@Override
public List<T> findPage(String hql, String[] param, int page, int size) {
// TODO Auto-generated method stub
Session s=null;
List<T> list=null;
try{
s=HibernateUtil.getThreadLocalSession();
Query query=s.createQuery(hql);
if(param!=null){
for(int i=0;i<param.length;i++){
query.setParameter(i, param[i]);
}
}
query.setFirstResult((page-1)*size);
query.setMaxResults(size);
list=query.list();
}finally{HibernateUtil.clossSession();}
return list;
}
@Override
public int getCount(String hql, String[] param) {
// TODO Auto-generated method stub
int resu=0;
Session s=null;
try{
s=HibernateUtil.getThreadLocalSession();
Query query=s.createQuery(hql);
if(param!=null){
for(int i=0;i<param.length;i++){
query.setString(i, param[i]);
}
}
resu=Integer.valueOf(query.iterate().next().toString());
}finally{HibernateUtil.clossSession();}
return resu;
}
@Override
public List<T> findByFields(String hql, String[] fields, String condition) {
// TODO Auto-generated method stub
Session s=null;
String findhql=hql;
if(fields!=null&&condition!=null&&fields.length>0&&!condition.equals("")){
findhql=findhql+"where 1=1 and (";
for(int i=0;i<fields.length-1;++i){
findhql+=fields[i]+" like'%"+condition+"%' or";
}
findhql+=fields[fields.length-1]+" like '%"+condition+"%')";
}
try{
s=HibernateUtil.getThreadLocalSession();
Query query=s.createQuery(findhql);
List<T> list=query.list();
return list;
}finally{HibernateUtil.clossSession();}
}
}
两个Dao类
UserDao.java
package com.edu.dao.user;
import com.edu.dao.DaoHibernate;
import com.edu.model.user.User;
public class UserDao extends DaoHibernate<User>{
public User findBynameAndPassword(User user){
String hql="from User u where u.userName=? and u.userPassword=?";
String param[]={user.getUserName(),user.getUserPassword()};
User user1=this.findOne(hql, param);
return user1;
}
public User fingByname(User user){
String hql="from User u where u.userName=?";
String param[]={user.getUserName()};
User user1=this.findOne(hql, param);
return user1;
}
public int updatePassword(User user,String newpPassword){
User user1=this.findBynameAndPassword(user);
user1.setUserPassword(newpPassword);
return this.update(user);
}
}
CardDao.java
package com.edu.dao.card;
import java.util.ArrayList;
import java.util.List;
import com.edu.dao.DaoHibernate;
import com.edu.model.card.Card;
public class CardDao extends DaoHibernate<Card>{
public List<Card> findByCondition(String condition,String flag){
String hql="from Card";
String cardFields[]={"name","sex","department","mobile","phone","email","address"};
List<Card> card1=this.findByFields(hql,cardFields,condition);
List<Card> card2=new ArrayList<Card>();
for(Card card:card1){
if(card.getFlag().equals(flag)){
card2.add(card);
}
}
return card2;
}
public Card findById(int id,String flag){
Card card2=findById(Card.class,id);
if(card2.getFlag().equals(flag)){
return card2;
}else{
return null;
}
}
public int delete(int id){
return this.delete(Card.class,id);
}
public int deleteList(int[] ids){
return this.deleteList(Card.class,ids);
}
public int retrieve(int...ids){//将名片移到回收站
for(int id:ids){
Card card=this.findById(Card.class, id);
card.setFlag("");
this.update(card);
}
return ids.length;
}
public int revert(int...ids){//从回收站中还原名片
for(int id:ids){
Card card=this.findById(Card.class, id);
card.setFlag("0");
this.update(card);
}
return ids.length;
}
}
两个model类及其hbm.xml
User.java
package com.edu.model.user;
public class User {
private Integer id;
private String userName;
private String userPassword;
private String userRealName;
public User(String userName, String userPassword, String userRealName) {
super();
this.userName = userName;
this.userPassword = userPassword;
this.userRealName = userRealName;
}
public User() {
super();
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public String getUserRealName() {
return userRealName;
}
public void setUserRealName(String userRealName) {
this.userRealName = userRealName;
}
}
User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2021-11-12 8:37:52 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.edu.model.user.User" table="USER">
<id name="id" type="java.lang.Integer" access="field">
<column name="ID" />
<generator class="native" />
</id>
<property name="userName" type="java.lang.String">
<column name="USERNAME" />
</property>
<property name="userPassword" type="java.lang.String">
<column name="USERPASSWORD" />
</property>
<property name="userRealName" type="java.lang.String">
<column name="USERREALNAME" />
</property>
</class>
</hibernate-mapping>
Card.java
package com.edu.model.card;
public class Card {
private Integer id;
private String name;
private String sex;
private String department;
private String mobile;
private String phone;
private String email;
private String address;
private String flag;
/*create table card(
id int(10) primary key,
name char(20),
sex char(20),
department char(20),
mobile char(20),
phone char(20),
email char(20),
address char(20),
flag char(20)
);*/
public Card(String name, String sex, String department, String mobile,
String phone, String email, String address, String flag) {
super();
this.name = name;
this.sex = sex;
this.department = department;
this.mobile = mobile;
this.phone = phone;
this.email = email;
this.address = address;
this.flag = flag;
}
public Card() {
super();
}
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 getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
}
Card.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2021-11-12 8:41:35 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.edu.model.card.Card" table="CARD">
<id name="id" type="java.lang.Integer" access="field">
<column name="ID" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="sex" type="java.lang.String">
<column name="SEX" />
</property>
<property name="department" type="java.lang.String">
<column name="DEPARTMENT" />
</property>
<property name="mobile" type="java.lang.String">
<column name="MOBILE" />
</property>
<property name="phone" type="java.lang.String">
<column name="PHONE" />
</property>
<property name="email" type="java.lang.String">
<column name="EMAIL" />
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property>
<property name="flag" type="java.lang.String">
<column name="FLAG" />
</property>
</class>
</hibernate-mapping>
最重要的struts.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/user" extends="struts-default">
<action name="register" class="com.edu.action.user.UserAction" method="userRegister">
<result name="success">/register_success.jsp</result>
<result name="error">/register.jsp</result>
<result name="input">/register.jsp</result>
</action>
<action name="login" class="com.edu.action.user.UserAction" method="userLogin">
<result name="input">/login.jsp</result>
<result name="failure">/login.jsp</result>
<result name="success">/login_success.jsp</result>
</action>
</package>
</struts>
下面是一些jsp界面
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath()+"/";
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<html>
<head>
<title>登录界面</title>
</head>
<body>
<s:fielderror cssStyle="color.red"></s:fielderror>
<font color="red"><s:property value="msg"/></font>
<br>
<form method="post" action="<%=path%>user/login">
<table>
<tr>
<th colspan="2">用户登录</th>
</tr>
<tr>
<td align="right">用户名:</td>
<td><input type="text" name="user.userName"
value="${user.userName}" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="user.userPassword" /></td>
</tr>
<tr>
<td align="left"><input type="submit" value="登录" /></td>
<td>未注册者,请先注册,单击 <a href="<%=path%>register.jsp">注册</a></td>
</tr>
</table>
</form>
<br>
</body>
</html>
login_success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath()+"/";
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<html>
<head>
<title>登录成功</title>
</head>
<body>
欢迎你,${user.userRealName} ,你登入成功!!<br>
进入名片管理系统,请点击<a href="<%=basePath%>card/find">名片管理系统</a>
</body>
</html>
register.jsp
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath()+"/";
//String basePath = request.getScheme() + "://"
// + request.getServerName() + ":" + request.getServerPort()
// + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册页面</title>
</head>
<body>
<s:fielderror cssStyle="color: red"></s:fielderror>
<font color="red"><s:property value="msg" /></font><br>
<h3 align="left">欢迎注册我们的系统,请认真填写您的信息</h3>
<form name="register" action="<%=path%>user/register" method="post">
<table>
<tr>
<td align="right">账户名:</td>
<td><input type="text" name="user.userName" value="${user.userName}" ></td>
</tr>
<tr>
<td align="right">为您的账户设置密码:</td>
<td><input type="password" name="user.userPassword"></td>
</tr>
<tr>
<td align="right">再次确认您的密码:</td>
<td><input type="password" name="re_password" ></td>
<td></td>
</tr>
<tr>
<td align="right">真实姓名:</td>
<td><input type="text" name="user.userRealName" value="${user.userRealName}"></td>
<td></td>
</tr>
<tr>
<td> <input type="hidden" name="user.userId" value=""></td>
<td> <input type="hidden" name="user.flag" value="0"></td>
</tr>
<tr>
<td align="right"><input type="submit" value="提交"></td>
<td colspan="2"><input type="reset" value="重新填写"></td>
</tr>
</table>
</form>
</body>
</html>
register_success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<html>
<head>
<title>注册成功!</title>
</head>
<body >
<h3>恭喜,${user.userRealName},你成功注册了我们的管理系统!点此
<a href="<%=basePath%>login.jsp">登录</a>
</h3>
</body>
</html>
以下是一些还没实现功能的jsp,先写上,以后再完善
insert.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加名片</title>
</head>
<body>
<h3>添加名片</h3>
<s:form action="/card/insert" method="post">
<s:textfield label="姓名" name="card.name"></s:textfield>
<s:radio label="性别" list="#{'男':'男','女':'女'}" name="card.sex" value="'男'"></s:radio>
<s:textfield label="单位" name="card.department"></s:textfield>
<s:textfield label="手机" name="card.mobile"></s:textfield>
<s:textfield label="电话" name="card.phone"></s:textfield>
<s:textfield label="Email" name="card.email"></s:textfield>
<s:textfield label="地址" name="card.address"></s:textfield>
<table>
<tr>
<td><s:submit value="提交" theme="simple" /></td>
<td><s:reset value="取消" theme="simple" /></td>
</tr>
</table>
</s:form>
</body>
</html>
update.jsp
<%@ page pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head><title>修改名片</title></head>
<body>
<h2>修改名片信息</h2>
<s:form action="/card/update" method="post">
<s:hidden name="card.id"></s:hidden>
<s:textfield label="姓名" name="card.name" ></s:textfield>
<s:radio label="性别" list="#{'男':'男','女':'女'}" name="card.sex"></s:radio>
<s:textfield label="单位" name="card.department"></s:textfield>
<s:textfield label="手机" name="card.mobile"></s:textfield>
<s:textfield label="电话" name="card.phone"></s:textfield>
<s:textfield label="Email" name="card.email"></s:textfield>
<s:textfield label="地址" name="card.address"></s:textfield>
<table>
<tr>
<td><s:submit value="修改" theme="simple" /></td>
<td><s:reset value="取消" theme="simple" /></td>
</tr>
</table>
</s:form>
</body>
</html>
list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script>
function deleteconfirm(id){
if (confirm("确实要删除该记录吗?")){
location.href="<%=basePath%>card/delete?id=" + id;
}
}
function insert(){location.href="<%=basePath%>/card/insert.jsp";}
function retrieve(){location.href="<%=basePath%>card2/find";}// 进入回收站
function upload(){location.href="<%=basePath%>/upload.jsp";}
function download(){location.href="<%=basePath%>card/download";}
function selectall() {//全选
var a = f2.checkList.length;
if (a != undefined){
for (i = 0; i < a; i++)
f2.checkList[i].checked = true;
} else
f2.checkList.checked = true;
}
function unselectall() {//取消全选
var a = f2.checkList.length;
if (a != undefined){
for (i = 0; i < a; i++)
f2.checkList[i].checked = false;
} else
f2.checkList.checked = false;
}
function delchoose() {
if (confirm("确实要删除所选吗?")) {
document.f2.action="<%=basePath%>card/delecteList";
}
}
function moveToRetrieve(){
if (confirm("确实要将选择的记录移到回收站吗?")) {
document.f2.action="<%=basePath%>card/retrieve";
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>名片浏览与查询</title>
</head>
<body>
<h3 align="center">名片浏览与查询</h3>
<form action="<%=basePath%>card/find" method="post">
<div align="center">
名片搜索: <input name="condition" type="text" /> <input type="submit"
value="查询" />
</div>
</form>
<br>
<br>
<s:form method="post" name="f2">
<table align="center">
<tr>
<td><input type="button" value="添加" onclick="insert()" /></td>
<td><input type="button" value="全选" onclick="selectall()" /></td>
<td><input type="button" value="取消全选" onclick="unselectall()" /></td>
<td><input type="submit" value="彻底删除所选" onclick="delchoose()" /></td>
<td><input type="submit" value="将所选移到回收站" onclick="moveToRetrieve()" /></td>
<td><input type="button" value="导入名片" onclick="upload()" /></td>
<td><input type="button" value="导出查询结果" onclick="download()" /></td>
<td><input type="button" value="进入回收站" onclick="retrieve()" /></td>
</tr>
</table>
<table width="70%" border="0" cellpadding="3" cellspacing="1"
align="center">
<tr bgcolor="#8899cc">
<td></td>
<td>编号</td>
<td>姓名</td>
<td>性别</td>
<td>单位</td>
<td>手机</td>
<td>电话</td>
<td>Email</td>
<td>通讯地址</td>
<td>操作</td>
</tr>
<s:iterator var="card" value="listCard" status="list">
<tr>
<td><input type="checkbox" name="checkList" value="${card.id}"></td>
<td><s:property value="#card.id" /></td>
<td><s:property value="#card.name" /></td>
<td><s:property value="#card.sex" /></td>
<td><s:property value="#card.department" /></td>
<td><s:property value="#card.mobile" /></td>
<td><s:property value="#card.phone" /></td>
<td><s:property value="#card.email" /></td>
<td><s:property value="#card.address" /></td>
<td><a href="<%=basePath%>card/findupdate?id=${card.id}">修改</a>
<a href="javascript:deleteconfirm('${card.id}')">删除</a></td>
</tr>
</s:iterator>
</table>
</s:form>
</body>
</html>