1. 实验要求
使用MySQL建立图书数据库,包含两张表
Book {ISBN (PK), Title, AuthorID (FK), Publisher, PublishDate, Price}
Author {AuthorID (PK), Name, Age, Country}
输入作者名字,查询作者所著书目;
点击某本书题目时,展示图书详细信息和作者详细信息;
用户点击删除按钮,将对应行的图书从数据表中删除;
- 开发环境配置
- 在Eclipse中配置Struts2
如上图所示,将Struts2中的commons-fileupload-1.3.2.jar , commons-io-2.4.jar , commons-lang3-3.4.jar , commons-logging-1.1.3.jar , freemarker-2.3.23.jar , javassist-3.20.0-GA.jar , log4j-api-2.6.2.jar , log4j-core-2.6.2.jar , ognl-3.1.10.jar , struts2-core-2.5.2.jar
加入到WEB-INF的lib文件夹中
- 在Eclipse中配置MySQL
将下载的mysql-connecter中的 mysql-connector-java-5.1.20-bin.jar 加入到WEB-INF的lib文件夹中,右键build path,在libraries里面添加 mysql-connector-java-5.1.20-bin.jar
- 在Eclipse中配置Tomcat
下载好以后在Libraries上选择Add Library,选择Server Runtime,选择自己下载的tomcat版本。
- 图书SaaS设计
- 3.1.Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<display-name>Lab2_CRUD</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file> //首页
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
- 3.2.Struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.action.extension" value="html,action,do,"/>
<package name="crud" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>
<action name="list" class="top.sonack.crud.action.BookAction" method=“list"> //显示所有书目
<result name="success">/list.jsp</result>
<result name="confirmAuthorSuccess" type="redirect">/confirmAuthor.action</result>
</action>
<action name="listAuthors" class="top.sonack.crud.action.BookAction" method=“listAuthors”>//显示所有作者
<result name="success">/listAuthors.jsp</result>
</action>
<action name="deleteSingleBook" class="top.sonack.crud.action.BookAction" method="deleteBook">
<result name="success" type="redirect">/list.action</result>
</action>
<action name="deleteSelectedBook" class="top.sonack.crud.action.BookAction" method=“deleteBooks”>//删除选中书目
<result name="success" type="redirect">/list.action</result>
</action>
<action name="searchInput">
<result>/search.jsp</result>
</action>
<action name="searchBooks" class="top.sonack.crud.action.BookAction" method=“searchBooks”>//显示书目详细信息
<result name="success">