JavaWeb项目开发案例精粹-第2章投票系统-002配置文件及公共类
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">
<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="jfreechart-default">
<action name="addVote" class="com.sanqing.action.AddVoteAction">
<result name="success">/admin/addVote.jsp</result>
</action>
<action name="showVote" class="com.sanqing.action.ShowVoteAction">
<result name="success">/admin/showVote.jsp</result>
</action>
<action name="deleteVote" class="com.sanqing.action.DeleteVoteAction">
<result name="success" type="chain">showVote</result>
</action>
<action name="showVoteByChannel" class="com.sanqing.action.ShowVoteByChannelAction">
<result name="success">index.jsp</result>
<result name="input">index.jsp</result>
</action>
<action name="voteResult" class="com.sanqing.action.VoteResultAction">
<result name="success" type="chart">
<param name="width">400</param>
<param name="height">300</param>
</result>
</action>
<action name="doVote" class="com.sanqing.action.DoVoteAction">
<result name="success" type="chain">voteResult</result>
<result name="input" type="chain">showVoteByChannel</result>
</action>
</package>
</struts>
3.jfreechart-default.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/*
* $Id: struts-plugin.xml 651946 2008-04-27 13:41:38Z apetrelli $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>
<package name="jfreechart-default" extends="struts-default"> <result-types>
<result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult">
<param name="height">150</param>
<param name="width">200</param>
</result-type>
</result-types>
</package> </struts>
4.
package com.sanqing.util; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; public class DBConnection {
private static final String DBDRIVER = "com.mysql.jdbc.Driver" ; //驱动类类名
private static final String DBURL = "jdbc:mysql://localhost:3306/db_votemanage";//连接URL
private static final String DBUSER = "root" ; //数据库用户名
private static final String DBPASSWORD = "1234"; //数据库密码
public static Connection getConnection(){
Connection conn = null; //声明一个连接对象
try {
Class.forName(DBDRIVER); //注册驱动
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD); //获得连接对象
} catch (ClassNotFoundException e) { //捕获驱动类无法找到异常
e.printStackTrace();
} catch (SQLException e) { //捕获SQL异常
e.printStackTrace();
}
return conn;
}
public static void close(Connection conn) {//关闭连接对象
if(conn != null) { //如果conn连接对象不为空
try {
conn.close(); //关闭conn连接对象对象
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void close(PreparedStatement pstmt) {//关闭预处理对象
if(pstmt != null) { //如果pstmt预处理对象不为空
try {
pstmt.close(); //关闭pstmt预处理对象
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void close(ResultSet rs) {//关闭结果集对象
if(rs != null) { //如果rs结果集对象不为null
try {
rs.close(); //关闭rs结果集对象
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
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;
/*
* 分页信息辅助类
*/
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项目开发案例精粹-第2章投票系统-002配置文件及公共类的更多相关文章
- JavaWeb项目开发案例精粹-第2章投票系统-001设计
1.项目结构 2.数据库设计 # MySQL-Front 5.0 (Build 1.0) /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */; /*!40101 SET ...
- JavaWeb项目开发案例精粹-第2章投票系统-006view层
1.index.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...
- JavaWeb项目开发案例精粹-第2章投票系统-005实体层
1. package com.sanqing.bean; /** * * 投票选项类 * */ public class VoteOption { private int voteOptionID; ...
- JavaWeb项目开发案例精粹-第2章投票系统-004action层
1. package com.sanqing.action; import java.util.UUID; import com.opensymphony.xwork2.ActionSupport; ...
- JavaWeb项目开发案例精粹-第2章投票系统-003Dao层
1. package com.sanqing.dao; import java.util.List; import com.sanqing.bean.Vote; import com.sanqing. ...
- JavaWeb项目开发案例精粹-第6章报价管理系统-002辅助类及配置文件
1. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www ...
- JavaWeb项目开发案例精粹-第6章报价管理系统-05Action层
0. <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC &quo ...
- JavaWeb项目开发案例精粹-第3章在线考试系统-007View层
0.login.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...
- JavaWeb项目开发案例精粹-第6章报价管理系统-07View层
1. 2.back_index.html <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT= ...
随机推荐
- php中echo、print、print_r、printf的返回值
1.echo 无返回值,是一个语言结构.在输出多个参数时不可以使用小括号; 2.print返回值为1:如:$x = 0; echo print $x."<br/>";/ ...
- 基于PinnedSectionListView实现联系人通讯录并且点击打电话
PinnedSectionListView具体下载地址.使用方法和注意事项:http://www.cnblogs.com/zzw1994/p/4997601.html 怎么根据联系人姓名首字符顺序读取 ...
- Oracle内存组件理论篇一
目标 1.SGA结构 2.PGA结构 1.SGA Shared pool 1).共享池是对SQL.PL/SQL程序进行语法分析.编译.执行的内存区域. 在执行SELECT * FROM emp语句时, ...
- Png图片的透明部分穿透测试
private void Window_MouseMove(object sender, MouseEventArgs e){ NavBtnList.Clear(); Point mou ...
- 2014年互联网IT待遇(包括国内民企、外企、金融机构)
一.民企 1. 百度 13k*14.6,special 14~17k*14.6 开发类 13K*14.6 (2014) 测试类.前端类 12K*14.6 (2014) 2. 腾讯 11.5k*16,s ...
- java之jar命令详解
1. JAR 文件包 JAR 文件就是 Java Archive File,顾名思意,它的应用是与 Java 息息相关的,是 Java 的一种文档格式.JAR 文件非常类似 ZIP 文件——准确的说, ...
- 终于成为博客员的一员了,这是我的第一篇博文,写一个关于ul li内容宽度的问题和解决方案
第一次写博文,写一个刚才遇到的问题吧. 关于ul li文字长度不固定,一行显示多列.当指定宽度时,文字长度超过指定的li宽度时解决方案: 如下代码 <h4>发送对象(共10个会员)< ...
- iOS多线程GCD 研究
Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法. dispatch queue分成以下三种: 1)运行在主线程的Main queue,通过dispat ...
- 101个MySQL的调节和优化的Tips
MySQL 是一个功能强大的开源数据库.随着越来越多的数据库驱动的应用程序,人们一直在推动MySQL发展到它的极限.这里是101条调节和优化MySQL安装的技巧.一些技巧是针对特定的安装环境的,但这些 ...
- cxf简单实例
CXF是一个基于 Servlet 技术的 SOA 应用开发框架,简单来说,就是WebService的轻量级实现. 1.下载开发包:http://cxf.apache.org/download.html ...