com.book.action
1 查找所有书籍action
public class FindAllBookAction extends ActionSupport{
private BookService bookService;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
List<Book> bookList = new ArrayList<Book>();
bookList = bookService.findAllBooks();
ServletRequest request=ServletActionContext.getRequest();
request.setAttribute("books", bookList);
User u = (User) ActionContext.getContext().getSession().get("user");
if("admin".equals(u.getUsername())){
return "adminSuccess";
}
return "success";
}
public BookService getBookService() {
return bookService;
}
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
}
2 用户登录action
public class UserLoginAction extends ActionSupport{
private User user;
private UserService userService;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
if(userService.userLogin(user)){
User u = null;
u = userService.getUser(user);
System.out.println(u.getUsername());
ActionContext.getContext().getSession().put("user",u);
return "success";
}
return "false";
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}
3
public class AddBookAction extends ActionSupport{
private Book book;
private BookService bookService;
// 上传多个文件的集合文本
private List<File> upload;
// /多个上传文件的类型集合
private List<String> uploadContentType;
// 多个上传文件的文件名集合
private List<String> uploadFileName ;
@Override
public String execute() throws Exception {
ServletRequest request=ServletActionContext.getRequest();
// 把上传的文件放到指定的路径下
String path = ServletActionContext.getServletContext().getRealPath("/upload");
String pathImg = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort()
+ "\\ReadOnLine\\upload\\";
System.out.println(pathImg);
// 写到指定的路径中
File file = new File(path);
// 如果指定的路径没有就创建
if (!file.exists()) {
file.mkdirs();
}
if(upload!=null){
// 把得到的文件的集合通过循环的方式读取并放在指定的路径下
for (int i = 0; i < upload.size(); i++) {
try {
//list集合通过get(i)的方式来获取索引
FileUtils.copyFile(upload.get(i), new File(file, uploadFileName.get(i)));
System.out.println(uploadFileName.get(i)+"---------------------------");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Integer id = bookService.save(book);
if(id!=null){
return "success";
}
return "false";
}
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public BookService getBookService() {
return bookService;
}
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
public List<File> getUpload() {
return upload;
}
public void setUpload(List<File> upload) {
this.upload = upload;
}
public List<String> getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(List<String> uploadContentType) {
this.uploadContentType = uploadContentType;
}
public List<String> getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(List<String> uploadFileName) {
this.uploadFileName = uploadFileName;
}
4
public class DeleteBookAction extends ActionSupport{
private BookService bookService;
private int id;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
bookService.deleteById(id);
return "success";
}
public BookService getBookService() {
return bookService;
}
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
5
public class UpdateBookAction extends ActionSupport{
private BookService bookService;
private Book book;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
bookService.updateBook(book);
return "success";
}
public BookService getBookService() {
return bookService;
}
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
}
6
public class FindBookByIdAction extends ActionSupport{
private BookService bookService;
private int id;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
Book book = null;
book = bookService.getBookById(id);
ServletRequest request=ServletActionContext.getRequest();
request.setAttribute("book", book);
return "success";
}
public BookService getBookService() {
return bookService;
}
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
com.book.dao
1 书籍dao
public interface BookDao {
/**
* 加载book实例
* @param id 需要加载的book实例的主键值
* @return 返回加载的book实例
*/
Book get(Integer id);
/**
* 保存book实例
* @param book 需要保存的book实例
* @return 刚刚保存的book实例的标识属性值
*/
Integer save(Book book);
/**
* 修改book实例
* @param book 需要修改的book实例
*/
void update(Book book);
/**
* 删除book实例
* @param id 需要删除的book实例的标识属性值
*/
void delete(Integer id);
/**
* 删除book实例
* @param book 需要删除的book实例
*/
void delete(Book book);
/**
* 根据书名查找Book
* @param name 查询的书名
* @return 指定书名对应的全部Book
*/
List<Book> findByName(String name);
/**
* 查询全部Book实例
* @return 全部Book实例
*/
public List<Book> findAllBook();
}
2 用户dao
public interface UserDao {
/**
* 加载User实例
* @param id 需要加载的User实例的主键值
* @return 返回加载的User实例
*/
User get(Integer id);
/**
* 保存User实例
* @param User 需要保存的User实例
* @return 刚刚保存的User实例的标识属性值
*/
Integer save(User user);
/**
* 修改User实例
* @param User 需要修改的User实例
*/
void update(User user);
/**
* 删除User实例
* @param id 需要删除的User实例的标识属性值
*/
void delete(Integer id);
/**
* 删除User实例
* @param User 需要删除的User实例
*/
void delete(User user);
/**
* 根据书名查找User
* @param name 查询的书名
* @return 指定书名对应的全部User
*/
List<User> findByName(String name);
/**
* 查询全部User实例
* @return 全部User实例
*/
public List<User> findAllUser();
/**
* 根据用户名和密码查询用户
* @param name 用户名
* @param pass 密码
* @return 返回用户实例信息
*/
public User getUserByNameAndPass(String name,String pass);
}
com.book.dao.impl
1 书籍dao实现类
public class BookDaoImpl extends HibernateDaoSupport implements BookDao{
@Override
public Book get(Integer id) {
// TODO Auto-generated method stub
return getHibernateTemplate().get(Book.class, id);
}
@Override
public Integer save(Book book) {
// TODO Auto-generated method stub
return (Integer)getHibernateTemplate().save(book);
}
@Override
public void update(Book book) {
// TODO Auto-generated method stub
getHibernateTemplate().update(book);
}
@Override
public void delete(Integer id) {
// TODO Auto-generated method stub
getHibernateTemplate().delete(get(id));
}
@Override
public void delete(Book book) {
// TODO Auto-generated method stub
getHibernateTemplate().delete(book);
}
@Override
public List<Book> findByName(String name) {
// TODO Auto-generated method stub
List<Book> list = new ArrayList<Book>();
list = getHibernateTemplate().find("from Book b where b.bookname like ?",name);
return list;
}
@Override
public List<Book> findAllBook() {
// TODO Auto-generated method stub
List<Book> list = new ArrayList<Book>();
list = getHibernateTemplate().find("from Book");
return list;
}
}
2 用户dao实现类
public class UserDaoImpl extends HibernateDaoSupport implements UserDao{
@Override
public User get(Integer id) {
// TODO Auto-generated method stub
return getHibernateTemplate().get(User.class, id);
}
@Override
public Integer save(User user) {
// TODO Auto-generated method stub
return (Integer)getHibernateTemplate().save(user);
}
@Override
public void update(User user) {
// TODO Auto-generated method stub
getHibernateTemplate().update(user);
}
@Override
public void delete(Integer id) {
// TODO Auto-generated method stub
getHibernateTemplate().delete(get(id));
}
@Override
public void delete(User user) {
// TODO Auto-generated method stub
getHibernateTemplate().delete(user);
}
@Override
public List<User> findByName(String name) {
// TODO Auto-generated method stub
List<User> list = new ArrayList<User>();
list = getHibernateTemplate().find("from User u where u.username like ?",name);
return list;
}
@Override
public List<User> findAllUser() {
// TODO Auto-generated method stub
List<User> list = new ArrayList<User>();
list = getHibernateTemplate().find("from User");
return list;
}
@Override
public User getUserByNameAndPass(String name, String pass) {
// TODO Auto-generated method stub
List<User> list = new ArrayList<User>();
list = getHibernateTemplate().find("from User u where u.username = ? and u.userpwd = ?",name,pass);
return list.get(0);
}
}
com.book.pojo
1 书籍实体
public class Book {
private int bookid;
private String bookname;
private String actorname;
private String bookinfo;
private String actorinfo;
private String date;
private String bookimage;
private String bookUrl;
public int getBookid() {
return bookid;
}
public void setBookid(int bookid) {
this.bookid = bookid;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public String getActorname() {
return actorname;
}
public void setActorname(String actorname) {
this.actorname = actorname;
}
public String getBookinfo() {
return bookinfo;
}
public void setBookinfo(String bookinfo) {
this.bookinfo = bookinfo;
}
public String getActorinfo() {
return actorinfo;
}
public void setActorinfo(String actorinfo) {
this.actorinfo = actorinfo;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getBookimage() {
return bookimage;
}
public void setBookimage(String bookimage) {
this.bookimage = bookimage;
}
public String getBookUrl() {
return bookUrl;
}
public void setBookUrl(String bookUrl) {
this.bookUrl = bookUrl;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + bookid;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Book other = (Book) obj;
if (bookid != other.bookid)
return false;
return true;
}
}
2 用户实体
public class User {
private int userid;
private String username;
private String userpwd;
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpwd() {
return userpwd;
}
public void setUserpwd(String userpwd) {
this.userpwd = userpwd;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + userid;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (userid != other.userid)
return false;
return true;
}
}
Book.hbm.xml 书籍hibernate配置文件
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.book.pojo">
<class name="Book" table="bookinfo">
<!-- 映射标识属性 -->
<id name="bookid" column="bookid"
type="int">
<!-- 指定主键生成器策略 -->
<generator class="identity"/>
</id>
<!-- 映射普通属性 -->
<property name="bookname" type="string"/>
<property name="actorname" type="string"/>
<property name="bookinfo" type="string"/>
<property name="actorinfo" type="string"/>
<property name="date" type="string"/>
<property name="bookimage" type="string"/>
<property name="bookUrl" type="string"/>
</class>
</hibernate-mapping>
User.hbm.xml 用户hibernate配置文件
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.book.pojo">
<class name="User" table="user">
<!-- 映射标识属性 -->
<id name="userid" column="userid"
type="int">
<!-- 指定主键生成器策略 -->
<generator class="identity"/>
</id>
<!-- 映射普通属性 -->
<property name="username" type="string"/>
<property name="userpwd" type="string"/>
</class>
</hibernate-mapping>
com.book.service
1
public interface BookService {
/**
* 查询所有的书籍信息
* @return 返回所有书籍
*/
public List<Book> findAllBooks();
/**
*保存书籍到数据库中
* @param book 实例
* @return 保存book的id
*/
public Integer save(Book book);
/**
* 根据ID删除
* @param id book主键id
*/
public void deleteById(Integer id);
/**
* 更新书籍信息
* @param book 书籍实例
*/
public void updateBook(Book book);
/**
* 根据id查询书籍
* @param id 主键信息
* @return 书籍实例
*/
public Book getBookById(Integer id);
}
2
public interface UserService {
/**
* 用户登录服务
* @param user 用户实例
* return boolean ; false 代表登录失败,true代表登录成功
*/
public boolean userLogin(User user);
/**
* 用户注册服务
* @param user 用户实例
* @return false 代表注册失败,true代表注册成功
*/
public boolean userRegist(User user);
/**
* 获取用户信息
* @param user 页面发送的用户
* @return 数据库中保存的用户信息
*/
public User getUser(User user);
}
com.book.service.impl
1
public class BookServiceImpl implements BookService{
private BookDao bookDao;
public void setBookDao(BookDao bookDao)
{
this.bookDao=bookDao;
}
@Override
public List<Book> findAllBooks() {
// TODO Auto-generated method stub\
List<Book> bookList = new ArrayList<Book>();
bookList = bookDao.findAllBook();
return bookList;
}
@Override
public Integer save(Book book) {
// TODO Auto-generated method stub
return bookDao.save(book);
}
@Override
public void deleteById(Integer id) {
// TODO Auto-generated method stub
bookDao.delete(id);
}
@Override
public void updateBook(Book book) {
// TODO Auto-generated method stub
bookDao.update(book);
}
public Book getBookById(Integer id){
return bookDao.get(id);
}
}
2
public class UserServiceImpl implements UserService{
private UserDao userDao;
public void setUserDao(UserDao userDao)
{
this.userDao=userDao;
}
@Override
public boolean userLogin(User user) {
// TODO Auto-generated method stub
User user1 = null;
user1 = userDao.getUserByNameAndPass(user.getUsername(), user.getUserpwd());
boolean flag = false;
if(user1 != null){
flag = true;
}
return flag;
}
@Override
public boolean userRegist(User user) {
// TODO Auto-generated method stub
return false;
}
@Override
public User getUser(User user) {
// TODO Auto-generated method stub
User user1 = null;
user1 = userDao.getUserByNameAndPass(user.getUsername(), user.getUserpwd());
return user1;
}
}
struts.xml
<?xml version="1.0" encoding="GBK"?>
<!-- 指定Struts2配置文件的DTD信息 -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<!-- Struts2配置文件的根元素 -->
<struts>
<!-- 配置了系列常量 -->
<constant name="struts.custom.i18n.resources" value="resource"/>
<constant name="struts.i18n.encoding" value="utf-8"/>
<constant name="struts.devMode" value="true"/>
<package name="default" extends="struts-default">
<action name="registPro" class="registAction">
<result name="success">/WEB-INF/content/success.jsp</result>
<result name="error">/WEB-INF/content/error.jsp</result>
</action>
<action name="userLoginAction" class="userLoginAction">
<result name="success" type="redirect">/findAllBookAction</result>
</action>
<action name="findAllBookAction" class="findAllBookAction">
<result name="success">/book/showAllBooks.jsp</result>
<result name="adminSuccess">/book/adminShowAllBooks.jsp</result>
</action>
<action name="addBookAction" class="addBookAction">
<result name="success" type="redirect">/findAllBookAction</result>
<result name="false">/WEB-INF/book/error.jsp</result>
<!-- 通过拦截器来限制上传图片的类型和大小 -->
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/bmp,image/x-png,image/gif</param>
<param name="maximumSize">2000</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
<action name="deleteBookAction" class="deleteBookAction">
<result name="success" type="redirect">/findAllBookAction</result>
</action>
<action name="updateBookAction" class="updateBookAction">
<result name="success" type="redirect">/findAllBookAction</result>
</action>
<action name="findBookByIdAction" class="findBookByIdAction">
<result name="success">/book/editbook.jsp</result>
</action>
</package>
</struts>
book
addbook.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
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>Insert title here</title>
</head>
<style>
body{
background-color: #B1C6A0;
}
.heade{
position:absolute;
top:-3px;
right:6px;
width:300px;
}
table{
width:1000px;
height:500px;
border-style: solid;
border-color: gray;
}
</style>
<script type="text/javascript">
function addBook(){
window.open("/book/addbook.jsp");
}
</script>
<body>
<div class="heade">
<p>用户名:${user.username }</p>
</div>
<form action="addBookAction" method="post">
<table>
<tr>
<td colspan="2" align="center"><h2>添加书籍</h2></td>
</tr>
<tr>
<td>书名:</td><td><input name="book.bookname" id="book.bookname" type="text" style="width: 250px; "></td>
</tr>
<tr>
<td>作者:</td><td><input name="book.actorname" id="book.actorname" type="text" style="width: 250px; "></td>
</tr>
<tr>
<td>上传日期:</td><td><input name="book.date" id="book.date" type="date" style="width: 250px; "></td>
</tr>
<tr>
<td>上传图片:</td><td><input name="bookImg" type="file" id="bookImg"></td>
</tr>
<tr>
<td>上传书籍:</td><td><input name="bookFile" type="file" id="bookFile"></td>
</tr>
<tr>
<td>书籍信息:</td><td><textarea rows="13" cols="120" name="book.bookinfo" id="book.bookinfo"></textarea></td>
</tr>
<tr>
<td>作者信息:</td><td><textarea rows="13" cols="120" name="book.actorinfo" id="book.actorinfo"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
2 adminShowAllBooks.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
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>Insert title here</title>
</head>
<style>
body{
background-color: #B1C6A0;
}
.heade{
position:absolute;
top:-3px;
right:6px;
width:300px;
}
table{
position:absolute;
left:400px;
width:1000px;
border-style: solid;
border-color: gray;
border-collapse:collapse;
}
tr{
border: 1 solid;
border-color: gray;
height: 30px;
}
td{
border:1px gray solid;
text-align: center;
}
</style>
<script type="text/javascript">
function addBook(){
window.open("/book/addbook.jsp");
}
</script>
<body>
<div class="heade">
<p>用户名:${user.username }</p>
</div>
<h2>所有书籍信息</h2>
<div class="operate">
<p><a href="<%=basePath%>/book/addbook.jsp" target="_blank">添加书籍</a></p>
</div>
<table>
<tr><td colspan="4">书籍列表</td></tr>
<tr>
<td width="100px">书名</td><td width="100px">作者</td><td>简介</td><td width="100px">操作</td>
</tr>
<c:forEach items="${books}" var="book">
<tr>
<td>${book.bookname}</td><td>${book.actorname }</td><td>${book.bookinfo }</td><td><a href="<%=basePath%>deleteBookAction?id=${book.bookid }">删除</a><a href="<%=basePath%>findBookByIdAction?id=${book.bookid }">编辑</a></td>
</tr>
</c:forEach>
</table>
</body>
</html>
3 showAllBooks.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
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>Insert title here</title>
</head>
<style>
body{
background-color: #B1C6A0;
}
.heade{
position:absolute;
top:-3px;
right:6px;
width:300px;
}
</style>
<script type="text/javascript">
function addBook(){
window.open("/book/addbook.jsp");
}
</script>
<body>
<div class="heade">
<p>用户名:${user.username }</p>
</div>
<h2>所有书籍信息</h2>
<div class="listbookinfo" id="booklist">
<c:forEach items="${books}" var="book">
<div class="book" id="book">
<div class="img" id="img">
<img alt="图书图片" src="${book.bookimage}">
</div>
<div class="msg" id="msg">
<p>书名:${book.bookname} </p>
<p>作者:${book.actorname }</p>
<p>简介:${book.bookinfo }</p>
</div>
</div>
</c:forEach>
</div>
</body>
</html>
login.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!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>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.8.2.js">
</script>
</head>
<script type="text/javascript">
$(document).ready(function(){
//alert(1111);
});
</script>
<style>
body{
background-color: #B1C6A0;
}
table{
position: absolute;
top: 3in;
left: 7in;
width: 400px;
height: 100px;
}
tr{
height: 50px;
}
</style>
<body>
<form action="userLoginAction" method="post">
<table>
<tr>
<td colspan="2" align="center">用户登录</td>
</tr>
<tr>
<td>用户名:</td><td><input type="text" id="user.username" name="user.username" style="width: 251px;height: 30px"></td>
</tr>
<tr>
<td>密 码:</td><td><input type="text" id="user.userpwd" name="user.userpwd" style="width: 251px;height: 30px"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="登录"> <input type="button" value="注册"></td>>
</tr>
</table>
</form>
</body>
</html>
editbook.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
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>Insert title here</title>
</head>
<style>
body{
background-color: #B1C6A0;
}
.heade{
position:absolute;
top:-3px;
right:6px;
width:300px;
}
table{
width:1000px;
height:500px;
border-style: solid;
border-color: gray;
}
</style>
<script type="text/javascript">
function addBook(){
window.open("/book/addbook.jsp");
}
</script>
<body>
<div class="heade">
<p>用户名:${user.username }</p>
</div>
<form action="addBookAction" method="post">
<input type="hidden" value="${book.bookimage }" id="book.bookimage" name="book.bookimage">
<input type="hidden" value="${book.bookUrl }" id="book.bookUrl" name="book.bookUrl">
<table>
<tr>
<td colspan="2" align="center"><h2>编辑书籍</h2></td>
</tr>
<tr>
<td>书名:</td><td><input name="book.bookname" id="book.bookname" type="text" style="width: 250px; " value="${book.bookname }"></td>
</tr>
<tr>
<td>作者:</td><td><input name="book.actorname" id="book.actorname" type="text" style="width: 250px;" value="${book.actorname }"></td>
</tr>
<tr>
<td>上传日期:</td><td><input name="book.date" id="book.date" type="date" style="width: 250px; " value="${book.date }"></td>
</tr>
<tr>
<td>上传图片:</td><td><input name="bookImg" type="file" id="bookImg"></td>
</tr>
<tr>
<td>上传书籍:</td><td><input name="bookFile" type="file" id="bookFile"></td>
</tr>
<tr>
<td>书籍信息:</td><td><textarea rows="13" cols="120" name="book.bookinfo" id="book.bookinfo" value="${book.bookinfo }"></textarea></td>
</tr>
<tr>
<td>作者信息:</td><td><textarea rows="13" cols="120" name="book.actorinfo" id="book.actorinfo" value="${book.actorinfo }"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
applicationContext.xml
<?xml version="1.0" encoding="GBK"?>
<!-- 指定Spring配置文件的Schema信息 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="userService" class="com.book.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"/>
</bean>
<bean id="bookService" class="com.book.service.impl.BookServiceImpl">
<property name="bookDao" ref="bookDao"/>
</bean>
<bean id="userLoginAction" class="com.book.action.UserLoginAction" scope="prototype">
<property name="userService" ref="userService" />
</bean>
<bean id="findAllBookAction" class="com.book.action.FindAllBookAction" scope="prototype">
<property name="bookService" ref="bookService" />
</bean>
<bean id="addBookAction" class="com.book.action.AddBookAction" scope="prototype">
<property name="bookService" ref="bookService" />
</bean>
<bean id="deleteBookAction" class="com.book.action.DeleteBookAction" scope="prototype">
<property name="bookService" ref="bookService" />
</bean>
<bean id="updateBookAction" class="com.book.action.UpdateBookAction" scope="prototype">
<property name="bookService" ref="bookService" />
</bean>
<bean id="findBookByIdAction" class="com.book.action.FindBookByIdAction" scope="prototype">
<property name="bookService" ref="bookService" />
</bean>
</beans>
daoContext.xml
<?xml version="1.0" encoding="GBK"?>
<!-- 指定Spring配置文件的Schema信息 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<!-- 指定连接数据库的驱动 -->
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<!-- 指定连接数据库的URL -->
<property name="jdbcUrl" value="jdbc:mysql://localhost/readonline"/>
<!-- 指定连接数据库的用户名 -->
<property name="user" value="root"/>
<!-- 指定连接数据库的密码 -->
<property name="password" value="1q2w3e4r"/>
<!-- 指定连接数据库连接池的最大连接数 -->
<property name="maxPoolSize" value="40"/>
<!-- 指定连接数据库连接池的最小连接数 -->
<property name="minPoolSize" value="1"/>
<!-- 指定连接数据库连接池的初始化连接数 -->
<property name="initialPoolSize" value="1"/>
<!-- 指定连接数据库连接池的连接的最大空闲时间 -->
<property name="maxIdleTime" value="20"/>
</bean>
<!-- 定义Hibernate的SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 依赖注入数据源,注入正是上面定义的dataSource -->
<property name="dataSource" ref="dataSource"/>
<!-- mappingResouces属性用来列出全部映射文件 -->
<property name="mappingResources">
<list>
<!-- 以下用来列出Hibernate映射文件 -->
<value>com/book/pojo/Book.hbm.xml</value>
<value>com/book/pojo/User.hbm.xml</value>
</list>
</property>
<!-- 定义Hibernate的SessionFactory的属性 -->
<property name="hibernateProperties">
<!-- 配置Hibernate属性 -->
<value>
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true;
</value>
</property>
</bean>
<bean id="bookDao" class="com.book.dao.impl.BookDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="userDao" class="com.book.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="GBK"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,
/WEB-INF/daoContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<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>
使用该系统中的所有jar包:http://down.51cto.com/data/1034096