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. ajax 设置Access-Control-Allow-Origin实现跨域访问

    ajax跨域访问是一个老问题了,解决方法很多,比较常用的是JSONP方法,JSONP方法是一种非官方方法,而且这种方法只支持GET方式,不如POST方式安全. 即使使用jquery的jsonp方法,t ...

  2. mysql时间处理

    两种方式,一个是在数据库查询的时候就截取,另一个就是在使用的时候截取. 1.数据库 select date_format(日期字段,’%Y-%m-%d’) as ‘日期’ from test 2.ja ...

  3. css透明(支持各浏览器)

    opacity: 0.4;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=40); -ms-filter: "progid:D ...

  4. Linux下如何卸载HP_LoadGenerator

    很简单的一句命令就可以完全卸载! rpm -e LoadGenerator

  5. .NET开发Windows Service程序 - Topshelf

    在实际项目开发过程中,会经常写一些类似定时检查,应用监控的应用.这类应用在windows平台通常都会写成window service程序. 在百度上搜索一下'c#开发windows service', ...

  6. 用Python作GIS之二:STARS开发环境配置

    STARS的一般使用可以通过REGAL网页快速学习http://regionalanalysislab.org/?n=STARS再次不做详细介绍这里关注的主题是对STARS源代码分析即为使用Pytho ...

  7. Seafile V4.1 安装笔记

    yum -y install gcc gcc-c++ make cmake pcre pcre-devel expat expat-devel curl wget mlocate gd gd-deve ...

  8. python之方法总结

    python的OOP的方法有3种: 1. 实例方法: 接收self参数 2. 类方法: 接收cls参数, 并要用classmethod()注册或者@classmethod注解. 3. 静态方法: 不接 ...

  9. ios7.0结合storyborad实现页面跳转的总结

    折腾了一整天,本文总结一下ios7.0页面跳转有关的内容 storyboard的潜规则 我接触ios很晚,环境已经是xcode5+ios7,所以对以前的IOS开发模式并不了解.在网上查阅了很多资料,发 ...

  10. win2008修改最大远程桌面连接数

    win2008修改最大远程桌面连接数 运行——gredit.msc——管理模板——windows组件——远程桌面服务——远程桌面回话主机——连接——限制连接的数量——修改为999999