1.

 <?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">
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<filter> <!--定义核心Filter FilterDispatcher -->
<filter-name>struts2</filter-name> <!-- 定义核心Filter的名称 -->
<filter-class> <!--定义核心Filter的实现类 -->
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name><!--核心Filter的名称 -->
<url-pattern>/*</url-pattern><!--使用该核心Filter过滤所有的Web请求 -->
</filter-mapping>
</web-app>

2.

 <?xml version="1.0" encoding="UTF-8" ?><!-- XML声明 -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd"><!-- 指定Struts 2配置文件的DTD信息 -->
<struts><!-- 根节点 -->
<constant name="struts.i18n.encoding" value="gb2312"></constant>
<package name="struts2" extends="struts-default">
<action name="login" class="com.sanqing.action.LoginAction">
<result name="studentSuccess" type="chain">getRandomSubject</result><!--进入考试页面-->
<result name="teacherSuccess" type="redirect">/teacher/index.html</result><!--老师登录成功页面-->
<result name="input">/login.jsp</result><!--登录失败页面-->
</action>
<action name="subjectAdd" class="com.sanqing.action.SubjectAddAction">
<result name="success" type="redirect">/teacher/subjectAdd.jsp</result><!--重定向到试题添加页面-->
<result name="input">/teacher/subjectAdd.jsp</result><!--请求转发到试题添加页面-->
</action>
<action name="subjectQuery" class="com.sanqing.action.QuerySubjectAction">
<result name="success">/teacher/subjectManage.jsp</result><!--跳转到试题列表管理页面-->
</action>
<action name="subjectParticular" class="com.sanqing.action.SubjectParticularAction">
<result name="success">/teacher/subjectShow.jsp</result><!--跳转到试题详细显示页面-->
</action>
<action name="subjectUpadateBefore" class="com.sanqing.action.SubjectUpdateBefore">
<result name="success">/teacher/subjectUpdate.jsp</result><!--跳转到试题更新页面-->
</action>
<action name="subjectUpadate" class="com.sanqing.action.SubjectUpdateAction">
<result name="success">/teacher/subjectUpdate.jsp</result><!--跳转到试题更新页面-->
</action>
<action name="subjectLikeQuery" class="com.sanqing.action.LikeQuerySubjectAction">
<result name="success">/teacher/subjectManage.jsp</result><!--跳转到试题列表管理页面-->
</action>
<action name="getRandomSubject" class="com.sanqing.action.GetRandomSubject">
<result name="success">/student/index.jsp</result><!--跳转到考试页面-->
</action>
<action name="submitExam" class="com.sanqing.action.SubmitExamAction">
<result name="success">/student/examResult.jsp</result><!--跳转到考试页面-->
</action>
<action name="showSubjectAnswer" class="com.sanqing.action.ShowSubjectAnswer">
<result name="success">/student/showAnswer.jsp</result><!--跳转到考试页面-->
</action>
<action name="queryStudentByName" class="com.sanqing.action.QueryStudentByName">
<result name="success">/teacher/studentManage.jsp</result><!--跳转到学生管理页面-->
</action>
<action name="queryStudentByClass" class="com.sanqing.action.QueryStudentByClass">
<result name="success">/teacher/studentManage.jsp</result><!--跳转到学生管理页面-->
</action>
</package>
</struts>

3.

 <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect</property> <!-- 数据库方言 -->
<property name="connection.url">
jdbc:mysql://localhost:3306/db_examsystem</property><!-- 数据库连接URL -->
<property name="connection.username">root</property> <!-- 数据库用户名 -->
<property name="connection.password">1234</property> <!-- 数据库用户密码 -->
<property name="connection.driver_class"> <!-- 数据库驱动类 -->
com.mysql.jdbc.Driver</property>
<mapping resource="com/sanqing/po/Student.hbm.xml"/>
<mapping resource="com/sanqing/po/Teacher.hbm.xml"/>
<mapping resource="com/sanqing/po/Subject.hbm.xml"/>
</session-factory>
</hibernate-configuration>

4.

 package com.sanqing.hibernate;

 import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration; public class HibernateSessionFactory {
private static String CONFIG_FILE_LOCATION
= "/hibernate.cfg.xml"; //指定配置文件路径
private static final ThreadLocal<Session> threadLocal
= new ThreadLocal<Session>(); //定义ThreadLocal对象
private static Configuration configuration
= new Configuration(); //定义Configuration对象
private static org.hibernate.SessionFactory sessionFactory;//定义SessionFactory对象
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);//读取配置文件
sessionFactory =
configuration.buildSessionFactory();//根据配置文件创建SessionFactory对象
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();//从ThreadLocal对象中获得Session对象
if (session == null || !session.isOpen()) {//判断获得的Session对象是否为空或者未打开
if (sessionFactory == null) {//如果没有创建SessionFactory对象,则首先创建
rebuildSessionFactory();
}
//如果SessionFactory对象不为空,则调用其openSession方法创建Session对象
session = (sessionFactory != null) ? sessionFactory.openSession(): null;
threadLocal.set(session);//在ThreadLocal对象中保存该Session对象
}
return session;
}
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);//读取配置文件
sessionFactory =
configuration.buildSessionFactory();//根据配置文件创建sessionFactory对象
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();//从ThreadLocal对象中获得Session对象
threadLocal.set(null);//将当前线程Session对象从ThreadLocal对象中移除
if (session != null) {
session.close();
}
}
public static org.hibernate.SessionFactory getSessionFactory() {//取得SessionFactory对象
return sessionFactory;
}
public static void setConfigFile(String configFile) {//设置新的配置文件
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}
public static Configuration getConfiguration() {//获得Configuration对象
return configuration;
}
}

5.

 package com.sanqing.util;
public class Page {
private int everyPage; //每页显示记录数
private int totalCount; //总记录数
private int totalPage; //总页数
private int currentPage; //当前页
private int beginIndex; //查询起始点
private boolean hasPrePage; //是否有上一页
private boolean hasNextPage; //是否有下一页
public Page(int everyPage, int totalCount, int totalPage,
int currentPage,int beginIndex, boolean hasPrePage,
boolean hasNextPage) { //自定义构造方法
this.everyPage = everyPage;
this.totalCount = totalCount;
this.totalPage = totalPage;
this.currentPage = currentPage;
this.beginIndex = beginIndex;
this.hasPrePage = hasPrePage;
this.hasNextPage = hasNextPage;
}
public Page(){} //默认构造函数
public int getEveryPage() { //获得每页显示记录数
return everyPage;
}
public void setEveryPage(int everyPage) {//设置每页显示记录数
this.everyPage = everyPage;
}
public int getTotalCount() {//获得总记录数
return totalCount;
}
public void setTotalCount(int totalCount) {//设置总记录数
this.totalCount = totalCount;
}
public int getTotalPage() {//获得总页数
return totalPage;
}
public void setTotalPage(int totalPage) {//设置总页数
this.totalPage = totalPage;
}
public int getCurrentPage() {//获得当前页
return currentPage;
}
public void setCurrentPage(int currentPage) {//设置当前页
this.currentPage = currentPage;
}
public int getBeginIndex() {//获得查询起始点
return beginIndex;
}
public void setBeginIndex(int beginIndex) {//设置查询起始点
this.beginIndex = beginIndex;
}
public boolean isHasPrePage() {//获得是否有上一页
return hasPrePage;
}
public void setHasPrePage(boolean hasPrePage) {//设置是否有上一页
this.hasPrePage = hasPrePage;
}
public boolean isHasNextPage() {//获得是否有下一页
return hasNextPage;
}
public void setHasNextPage(boolean hasNextPage) {//设置是否有下一页
this.hasNextPage = hasNextPage;
}
}

6.

 package com.sanqing.util;

 import java.util.List;

 public class PageResult {
private Page page; //分页信息
private List list; //记录信息
public PageResult(Page page, List list) {
this.page = page;
this.list = list;
}
public Page getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
}

7.

 package com.sanqing.util;
/*
* 分页信息辅助类
*/
public class PageUtil {
public static Page createPage(int everyPage,int totalCount,int currentPage) {//创建分页信息对象
everyPage = getEveryPage(everyPage);
currentPage = getCurrentPage(currentPage);
int totalPage = getTotalPage(everyPage, totalCount);
int beginIndex = getBeginIndex(everyPage, currentPage);
boolean hasPrePage = getHasPrePage(currentPage);
boolean hasNextPage = getHasNextPage(totalPage, currentPage);
return new Page(everyPage, totalCount, totalPage, currentPage,
beginIndex, hasPrePage, hasNextPage);
}
public static int getEveryPage(int everyPage) { //获得每页显示记录数
return everyPage == 0 ? 10 : everyPage;
}
public static int getCurrentPage(int currentPage) { //获得当前页
return currentPage == 0 ? 1 : currentPage;
}
public static int getTotalPage(int everyPage,int totalCount) {//获得总页数
int totalPage = 0;
if(totalCount != 0 &&totalCount % everyPage == 0) {
totalPage = totalCount / everyPage;
} else {
totalPage = totalCount / everyPage + 1;
}
return totalPage;
}
public static int getBeginIndex(int everyPage,int currentPage) {//获得起始位置
return (currentPage - 1) * everyPage;
}
public static boolean getHasPrePage(int currentPage) {//获得是否有上一页
return currentPage == 1 ? false : true;
}
public static boolean getHasNextPage(int totalPage, int currentPage) { //获得是否有上一页
return currentPage == totalPage || totalPage == 0 ? false : true;
}
}

JavaWeb项目开发案例精粹-第3章在线考试系统-002配置文件及辅助类的更多相关文章

  1. JavaWeb项目开发案例精粹-第3章在线考试系统-007View层

    0.login.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...

  2. JavaWeb项目开发案例精粹-第3章在线考试系统-006实体层

    1. package com.sanqing.po; /* * 学生表,保存学生编号,系统密码 */ public class Student { private String studentID; ...

  3. JavaWeb项目开发案例精粹-第3章在线考试系统-005action层

    1. <?xml version="1.0" encoding="UTF-8" ?><!-- XML声明 --> <!DOCTYP ...

  4. JavaWeb项目开发案例精粹-第3章在线考试系统-004Service层

    1. package com.sanqing.service; import java.util.List; import com.sanqing.po.Student; public interfa ...

  5. JavaWeb项目开发案例精粹-第3章在线考试系统-003Dao层

    1. package com.sanqing.dao; import java.util.List; import com.sanqing.po.Student; public interface S ...

  6. JavaWeb项目开发案例精粹-第3章在线考试系统-001设计

    1. 2. 3. 4. # MySQL-Front 5.0 (Build 1.0) /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */; /*!40101 SET SQL ...

  7. JavaWeb项目开发案例精粹-第6章报价管理系统-05Action层

    0. <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC &quo ...

  8. JavaWeb项目开发案例精粹-第6章报价管理系统-002辅助类及配置文件

    1. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www ...

  9. JavaWeb项目开发案例精粹-第2章投票系统-001设计

    1.项目结构 2.数据库设计 # MySQL-Front 5.0 (Build 1.0) /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */; /*!40101 SET ...

随机推荐

  1. [JS进阶] 编写可维护性代码 (1)

    今天的web应用大至成千上万行的javascript代码,执行各种复杂的过程,这种演化让我们开发者必须得对可维护性有一定的认识!编写可维护性代码很重要,很多情况下我们是以他人的工作成果为基础,确保代码 ...

  2. SQL中char,varchar,nvarchar等的异同

    比较这几个数据类型,总是忘记,可能比较细节的原因.先做个记号,回头完善.

  3. openwrt无线中继教程

    1.设置自己路由lan口的IP地址,网段不能跟上级路由的一样. 2.在无线标签下点击"扫描网络". 3.在新出现的界面中,会列出你附近的无线网络.点击你需要中继的网络右边的&quo ...

  4. Java 图形编程 一:入门

    package second; import java.awt.Color; import java.awt.Frame; import java.awt.event.WindowAdapter; i ...

  5. VirtualBox虚拟机安装MSDOS和MINIX2.0.0双系统

    1. 在VirtualBox中新建一个MSDOS虚拟机. 2.下载一个MSDOS软盘镜像. 3.启动虚拟机,提示选择安装盘时,选择步骤2下载过来的MSDOS镜像. 4.正常启动进入DOS命令行,用FD ...

  6. eclipse下mysql编程

    mysql -uroot -p 密码 1:如果/usr/include/mysql路径下不存在头文件请: apt-get install libmysql++安装开发包 2:程序中添加头文件<m ...

  7. Java线程同步(synchronized)——卖票问题

    卖票问题通常被用来举例说明线程同步问题,在Java中,采用关键字synchronized关键字来解决线程同步的问题. Java任意类型的对象都有一个标志位,该标志位具有0,1两种状态,其开始状态为1, ...

  8. java常用集合类:Deque,ArrayList,HashMap,HashSet

    图一:java collection 类图 Queue家族 无论是queue还是stack,现在常用的是Deque的实现类:如单线程的ArrayQueue,多线程的ArrayBlockingQueue ...

  9. 如何自定义Liferay 7 portal的Log in登录界面

    前提: 1. Liferay portal 7 2. Liferay IDE 3.0.1 Liferay现有的工具中提供了很多修改portal的模板,以满足开发者的各种自定义需求. 修改的原理是利用M ...

  10. 交互式shell和非交互式shell、登录shell和非登录shell的区别

    交互式shell和非交互式shell.登录shell和非登录shell的区别.首先,这是两个不同的维度来划分的,一个是是否交互式,另一个是是否登录. 交互式shell和非交互式shell(intera ...