JavaEE 实例 图书管理系统

软件151    马金忠css

1、打开数据库,成功链接数据库,并导入数据库数据,很简单 ,就不一一进行解释了。。。html

 

2、编写代码,编写主界面的代码和跳转页面等页面的代码,并调试运行成功:java

  主要的包和文件以下图:mysql

  其主要界面的部分代码: web

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<style type="text/css">
.style1{height:13px; width:67px;font-size:9px; align:center}
.style2{height:13px; width:62px;font-size:9px;}
</style>
</head>
<body bgcolor="#ffffff">
<table border="0" cellpadding="0" cellspacing="0" width="802">
<!-- 从Session中取出login -->
<s:set name="login" value="#session.login"></s:set>
<tr>
<td><img src="images/left.jpg" width="263" height="108" /></td>
<td><table align="left" border="0" cellpadding="0" cellspacing="0" width="539">
<tr>
<td><table align="left" border="0" cellpadding="0" cellspacing="0" width="539">
<tr><td><img src="images/title.jpg" width="310" height="72" /></td>
<td><table align="left" border="0" cellpadding="0" cellspacing="0" width="229">
<tr>
<td><img src="images/head.jpg" width="229" height="28"/></td>
</tr>
<tr>
<td><table align="left" border="0" cellpadding="0" cellspacing="0" width="229">
<!-- 若是login没值,表示未登陆 -->
<s:if test="#login==null">
<s:form theme="simple" action="login" method="post">
<tr><td><input name="login.name" type="text" class="style1"/></td>
<td><img src="images/password.jpg" width="42" height="15"/></td>
<td><input name="login.password" type="password" class="style2"/></td>
<td><input type="image" src="images/login.jpg" style="width:57;height=15"></td>
</tr>
</s:form></s:if>
<!-- 不然表示登陆,登陆后就为输入设置disabled,不可编辑 -->
<s:else><s:form theme="simple" action="login" method="post">
<tr><td><input name="login.name" type="text" class="style1" disabled/></td>
<td><img src="images/password.jpg" width="42" height="15"/></td>
<td><input name="login.password" type="password" class="style2" disabled/></td>
<td><input type="image" src="images/login.jpg" style="width:57;height=15" disabled></td>
</tr>
</s:form></s:else>
</table></td></tr>
<tr><td><img src="images/middle.jpg" width="229" height="29"/></td>
</tr></table></td>
</tr></table></td></tr>
<tr>
<td><table align="left" border="0" cellpadding="0" cellspacing="0" width="539">
<!-- 若是已经登陆,并且角色为管理员,true表示管理员,false表示学生
本例只作了2个功能,借书,和图书管理,若是要编写其余功能,只需在对应的图片后面
加入点击的触发事件本部分调用的图片里面的文字时发亮的,因此在页面的视觉效果为亮
的-->
<s:if test="(#login!=null)&&(#login.role==true)">
<tr>
<td><img src="images/booksearch.jpg" width="76" height="36" /></td>
<!-- 点击触发操做,style="cursor:hand"表示当鼠标移动到该图片是,
图标变成手状,下同 -->
<td><img src="images/lendsearch.jpg" width="74" height="36" /></td>
<td><img src="images/lend.jpg" width="72" height="36" onclick="location.href='lend.jsp'" style="cursor:hand"/></td>
<td><img src="images/giveback.jpg" width="71" height="36" /></td>
<td><img src="images/studentmanage.jpg" width="73" height="36" /></td>
<td><img src="images/bookmanage.jpg" width="71" height="36" onclick="location.href='bookmanage.jsp'" style="cursor:hand"/></td>
<td><img src="images/about.jpg" width="102" height="36" /></td>
</tr>
</s:if>
<!-- 若是已经登陆,并且角色为学生 ,后面功能的图片中的文字是灰的,因此页面效果功能是灰色的-->
<s:elseif test="(#login!=null)&&(#login.role==false)">
<tr>
<td><img src="images/booksearch.jpg" width="76" height="36" /></td>
<td><img src="images/lendsearch.jpg" width="74" height="36" /></td>
<td><img src="images/lend1.jpg" width="72" height="36" /></td>
<td><img src="images/giveback1.jpg" width="71" height="36" /></td>
<td><img src="images/studentmanage1.jpg" width="73" height="36" /></td>
<td><img src="images/bookmanage1.jpg" width="71" height="36" /></td>
<td><img src="images/about.jpg" width="102" height="36" /></td>
</tr></s:elseif>
<!-- 若前面两种否就表示未登陆,本部分调用的图片均为灰色的 -->
<s:else><tr>
<td><img src="images/booksearch1.jpg" width="76" height="36" /></td>
<td><img src="images/lendsearch1.jpg" width="74" height="36" /></td>
<td><img src="images/lend1.jpg" width="72" height="36" /></td>
<td><img src="images/giveback1.jpg" width="71" height="36" /></td>
<td><img src="images/studentmanage1.jpg" width="73" height="36" /></td>
<td><img src="images/bookmanage1.jpg" width="71" height="36" /></td>
<td><img src="images/about.jpg" width="102" height="36" /></td>
</tr></s:else></table></td>
</tr></table></td>
</tr></table>
</body>
</html>sql

图片以下:数据库

最主要的是链接数据库成功!apache

代码以下:api

package db;
import java.sql.*;
public class DBConn {
public static Connection conn;
//链接数据库
public static Connection getConn(){
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/book","root","123");
return conn;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
//关闭链接
public static void CloseConn(){
try{
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}tomcat

成功后,点击运行。。

固然运行的关键仍是在pom.xml的配置上 :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cqive</groupId>
<artifactId>add</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging><!-- 必须设置为war,tomcat7才能加载,而且该项目必须配置web.xml -->

<repositories><!--设置maven组件仓库 -->
<!-- maven官方仓库 -->
<repository>
<id>maven</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- 阿里巴巴发布版本仓库 -->
<repository>
<id>alibaba-opensource</id>
<name>alibaba-opensource</name>
<url>http://code.alibabatech.com/mvn/releases/</url>
<layout>default</layout>
</repository>
</repositories>

<build><!-- maven项目编译插件 -->
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<!-- <encoding>UTF-8</encoding> -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>

<configuration>
<!-- 使用内置的模拟Tomcat服务器 -->
<path>/book</path>
<uriEncoding>UTF-8</uriEncoding>
<port>9627</port>
<mode>context</mode>
<!-- <contextFile>src/main/webapp/META-INF/context.xml</contextFile> -->

<contextReloadable>true</contextReloadable>
<!-- <backgroundProcessorDelay>5</backgroundProcessorDelay> -->
</configuration>
</plugin>
</plugins>
</build>

<dependencies><!-- 项目依赖插件 -->

<!-- Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope> <!-- 编译时用到servlet-api和jsp-api,但在打包的时候不用这两个依赖 -->
</dependency>

<!-- JSP API -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope> <!-- 编译时用到servlet-api和jsp-api,但在打包的时候不用这两个依赖 -->
</dependency>

<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- Struts2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.1</version>
</dependency>
<!-- log4j -->
<!-- <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency> -->

<!-- 使用 Jackson把Java对象转换成 JSON -->
<!-- <dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
</dependency> -->

<!-- mysql数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>

<!-- druid数据库链接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>0.2.9</version>
</dependency>
</dependencies>
</project>

就这样,一个图书管理系统就实现了 ,虽然只展示了一部分的代码,可是仍是很高兴,最起码我作了,虽然只显示了部分的功能,可是只要努力了就会有回报。

相关文章
相关标签/搜索