JavaWeb课程设计

xxxx

信息科学与工程学院 课程设计

题 目: 客户信息管理系统

姓 名: xxxx

学 号: xxxx

班 级: xxxx

课 程: Java Web

任课教师 xxxx

20**年6月20日

课程设计任务书及成绩评定

目录

1.课程设计目的 1

2.系统设计 1

2.1系统特点 1

2.2功能设计 1

3.数据库设计 1

4.功能模块的详细设计 2

4.1数据库访问模块 2

4.2共通Servlet的处理 3

4.3登录模块 6

4.4客户资料录入 7

4.5客户资料修改 9

4.6客户资料删除 11

5.课程设计总结 14

1.课程设计目的

课程设计是一项重要的实践性教学环节,在教师的指导下,以学生为中心,充分调动学生的积极性和能动性,重视学生自学能力的培养。

通过本课程设计可以使学生充分认识开发和设计Web应用程序的的重要性和复杂性,充分了解Web应用程序的设计和开发的基本过程,掌握常用的Web开发技术,充分把握各项技术的特点和应用领域以及各项技术之间的相互关系,进一步体会各项技术在Web应用程序中地位和作用从而对各种技术有比较清醒的认识,在此基础上习得Web开发技术平台的选择能力。

2.系统设计

2.1系统特点

本系统尝试从一些简单的层面对于企业客户信息的管理进行一种探索,针对企业和客户的交流行为进行系统化管理,力求做到客户信息的准确、快捷和可追溯性。

本系统包括3个主要层面,客户信息维护、客户来电记录和客户回访记录。

2.2功能设计

(1)客户资料信息维护模块

客户信息输入、修改和删除。

(2)客户来电信息模块

来电信息添加和来电信息查询。

(3)客户回访信息模块

回访信息添加和回访信息查询。

3.数据库设计

(1)用户表user

https://upload.fanwen118.com/wk-img/img100/3785222_1.jpg

(2)客户信息表Customer

https://upload.fanwen118.com/wk-img/img100/3785222_2.jpg

(3)客户来电表 IncomeCall

https://upload.fanwen118.com/wk-img/img100/3785222_3.jpg

4.功能模块的详细设计

4.1数据库访问模块

数据库的设计是需要针对每个模块而不是每个页面进行设置数据库模块,所有的数据访问类DUser、DIncome、Dcustomer、DFeedback、DRemind从同一个父类Dcommom继承,该父类提供了一个方法getDBConnection来获取数据库的链接。

DCommon代码

public class DCommon

{

public Connection getDBConnection( )

{//尝试连接数据库

try

{ //载入MySQL的JDBC驱动类

Class.forName(CommonConst.DB_DRIVER_CLASSNAME);

Connectionconn=DriverManager.getConnection

( CommonConst.DB_CONN_STRING );//获得数据库连接

return conn;

}

catch(Exception ex)

{

ex.printStackTrace();

return null;

}

}

}

4.2共通Servlet的处理

本系统中一旦代码出现了异常,将直接向上抛出,一直抛到共通类Servlet进行处理。

在共通Servlet中发现异常,将页面跳转到错误处理页面,并把错误信息在页面上显示出来,同时提供一个往登录页面迁移的链接。

对应的共通Servlet的相关代码如下:

public class CommonServlet extends HttpServlet

{

//保存各页面Id对应的action类的对象

private Hashtable hPageHandler = new Hashtable();

//配置文件的存放位置

private JXPathContext configContext = null;

public void init()

{

//取得配置文件,并获得其中的dom元素

String filePath = getInitParameter("configXML");

String fileRealPath = getServletContext().getRealPath(filePath);

//尝试建立配置文件的DOM

try

{

org.jdom.input.SAXBuilder builder = new SAXBuilder();

org.jdom.Document pDoc = builder.build(fileRealPath );

configContext = JXPathContext.newContext(pDoc);

GlobalObjectProvider.init( configContext );

}

catch(Exception e)

{

System.out.println("Servlet初始化失败!");

}

//初始化共通类以获取页面信息

CommonConst.init();

}

//每一种动作第一次执行的时候,初始化对应的类

public void doPost ( HttpServletRequest request,

HttpServletResponse response )

throws ServletException, IOException

{

//设置提交表单的中文编码

request.setCharacterEncoding("GBK");

HttpSession mySession = request.getSession(true);

//得到用户输入信息

String sPageId = request.getParameter("pageId");

String sActionId = request.getParameter("actionId");

if ( sPageId == null || sPageId.equals("")

|| sActionId == null || sActionId.equals("") )

{

//非法进入页面,跳转到首页

mySession.invalidate();

response.sendRedirect("../login.jsp");

return;

}

//如果非法进入页面(登录页面除外)

if ( !sPageId.equals("S001")

&& mySession.getAttribute("loginUser") == null )

{

//非法进入页面,跳转到首页

mySession.invalidate();

response.sendRedirect("../login.jsp");

return;

}

try

{

//根据pageId获得处理对象,如果没有则创建一个对象

Object oActionObject = hPageHandler.get( sPageId );

if ( oActionObject == null )

{

//根据配置文件创建一个新对象

String sClassName = (String)configContext.getValue(

"ch08-config/page[@id='"+sPageId+"']/@className");

oActionObject = Class.forName( sClassName ).newInstance();

hPageHandler.put( sPageId, oActionObject);

}

//取得方法名

String sMethodName = (String)configContext.getValue(

"ch08-config/page[@id='"+sPageId+"']/action[@id='"+sActionId+"']/@methodName");

//生成对应的参数,并调用对应对象的对应方法

//inputData是根据传入的参数做成的

Hashtable inputData = new Hashtable();

Enumeration params = request.getParameterNames();

while( params.hasMoreElements())

{

String sParaName = (String)params.nextElement();

inputData.put( sParaName, request.getParameter(sParaName) );

}

//outputData是下一个页面的值域,在此只是被初始化

Hashtable outputData = new Hashtable();

//生成参数列表

Class[] paraType = { Class.forName("java.util.Hashtable"),

Class.forName("java.util.Hashtable"),

Class.forName("javax.servlet.http.HttpSession") };

Object[] paraObj = { inputData, outputData, mySession };

//生成Method对象

Method invokeMethod = oActionObject.getClass().getMethod( sMethodName, paraType );

//调用方法

invokeMethod.invoke( oActionObject, paraObj );

//根据outputData的结果决定下一个页面

String sNextPageId = (String)outputData.get("pageId");

String sRealPagePath = (String)configContext.getValue(

"ch08-config/page[@id='"+sNextPageId+"']/@path");

//设置下一个页面的值域

mySession.setAttribute( sNextPageId, outputData );

response.sendRedirect( sRealPagePath );

return;

}

catch(Exception e)

{

//页面处理出错,跳转到错误处理页面

e.printStackTrace();

Hashtable outputData = new Hashtable();

outputData.put( "exception", e );

//设置错误页面的值域

mySession.setAttribute( CommonConst.VIEWID_ERROR, outputData );

response.sendRedirect("../error.jsp");

return;

}

}

public void doGet ( HttpServletRequest request,

HttpServletResponse response )

throws ServletException, IOException

{

doPost( request, response );

}

}

4.3登录模块

由于本系统用户角色只有一种,不存在跳转到不同页面的问题,处理相对简单一些,如果用户登录成功,则将用户信息放到session中,并将页面跳转到导航页面。

(1)登录页面控制模块ALogin相关代码如下:

public class ALogin

{

public void doLogin ( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//获取输入信息

String sUsername = (String)inputData.get("username");

String sPassword = (String)inputData.get("password");

//校验用户输入信息

LUser lUser = (LUser)GlobalObjectProvider.getLogicService(CommonConst.LOGIC_KEY_USER);

//如果对应的类没有的话,报错并返回login页面

if ( lUser == null )

{

throw new Exception("发生了内部错误,请联系技术人员!" );

}

//获取用户信息

User userInfo = lUser.getUserInfo( sUsername, sPassword );

if ( userInfo == null )

{

outputData.put( "pageId", CommonConst.VIEWID_LOGIN );

outputData.put( "errMsg", "用户名密码检查失败!请重新输入。" );

outputData.put( "username", sUsername );

return;

}

else

{

outputData.put( "pageId", CommonConst.VIEWID_MENU);

//往session中设置用户信息

mySession.setAttribute( "loginUser", userInfo );

return;

}

}

}

(2)登录效果图

https://upload.fanwen118.com/wk-img/img100/3785222_4.jpg

4.4客户资料录入

单击导航页面链接进入客户资料录入页面。注意两个方面:一是页面对应的显示元素和输入元素的颜色和当前模块的颜色想吻合,而是在用户输入信息并单击“登录”按钮时,将客户信息登入数据库,然后页面直接转入修改一览。

页面控制类ACustomerAdd:

public class ACustomerAdd

{

//追加一个客户

public void doRegister( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//首先获得要追加的客户详细信息

String sRealname = (String)inputData.get("realname");

String sSex = (String)inputData.get("sex");

String sBirthday = (String)inputData.get("birthday");

String sPhone = (String)inputData.get("phone");

String sCellphone = (String)inputData.get("cellphone");

String sAddress = (String)inputData.get("address");

String sStartDate = (String)inputData.get("startDate");

String sMemo = (String)inputData.get("memo");

//生成一个Customer对象以调用

Customer customer = new Customer();

customer.setRealname( sRealname );

customer.setSex( sSex );

customer.setBirthday( sBirthday );

customer.setPhone( sPhone );

customer.setCellphone( sCellphone );

customer.setAddress( sAddress );

customer.setStartDate( sStartDate );

customer.setMemo( sMemo );

//调用对应的logic类

LCustomer lCustomer = (LCustomer)GlobalObjectProvider.getLogicService(CommonConst.LOGIC_KEY_CUSTOMER);

//添加对应的记录

lCustomer.addCustomer( customer );

//然后重新检索,并将页面迁移到一览页面

Vector vCustomers = lCustomer.getAllCustomer();

outputData.put( "pageId", CommonConst.VIEWID_CUSTOMER_LIST);

//往值域中设置当前位置信息

mySession.setAttribute("customers", vCustomers );

outputData.put( "pageIndex", new Integer(0) );

return;

}

}

效果图:

https://upload.fanwen118.com/wk-img/img100/3785222_5.jpg

4.5客户资料修改

public class ACustomerModify

{

//修改一个客户信息

public void doRegister( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//首先获得要修改的客户详细信息

String sCustomerId = (String)inputData.get("customerId");

String sRealname = (String)inputData.get("realname");

String sSex = (String)inputData.get("sex");

String sBirthday = (String)inputData.get("birthday");

String sPhone = (String)inputData.get("phone");

String sCellphone = (String)inputData.get("cellphone");

String sAddress = (String)inputData.get("address");

String sStartDate = (String)inputData.get("startDate");

String sMemo = (String)inputData.get("memo");

//生成一个Customer对象以调用

Customer customer = new Customer();

customer.setCustomerId( sCustomerId );

customer.setRealname( sRealname );

customer.setSex( sSex );

customer.setBirthday( sBirthday );

customer.setPhone( sPhone );

customer.setCellphone( sCellphone );

customer.setAddress( sAddress );

customer.setStartDate( sStartDate );

customer.setMemo( sMemo );

//调用对应的logic类

LCustomer lCustomer = (LCustomer)GlobalObjectProvider.getLogicService(CommonConst.LOGIC_KEY_CUSTOMER);

//添加对应的记录

lCustomer.modifyCustomer( customer );

//然后重新检索,并将页面迁移到一览页面

Vector vCustomers = lCustomer.getAllCustomer();

outputData.put( "pageId", CommonConst.VIEWID_CUSTOMER_LIST);

//往值域中设置当前位置信息

mySession.setAttribute("customers", vCustomers );

outputData.put( "pageIndex", new Integer(0) );

return;

}

}

https://upload.fanwen118.com/wk-img/img100/3785222_6.jpg

https://upload.fanwen118.com/wk-img/img100/3785222_7.jpg

4.6客户资料删除

public class ACustomerDelete

{

//到首页

public void doFirst( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//首页的index一定为0

outputData.put( "pageId", CommonConst.VIEWID_CUSTOMER_DELETE);

//往值域中设置当前位置信息

outputData.put( "pageIndex", new Integer(0) );

return;

}

//到末页

public void doLast( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//首先获得全部客户信息,并计算出最后一页的位置

Vector allCustomers = (Vector)mySession.getAttribute("customers");

int iMax = allCustomers.size();

int iMaxPage = (int)Math.ceil((double)iMax/20);

int iIndex = (iMaxPage-1)*20;

//首页的index一定为0

outputData.put( "pageId", CommonConst.VIEWID_CUSTOMER_DELETE);

//往值域中设置当前位置信息

outputData.put( "pageIndex", new Integer(iIndex) );

return;

}

//到前页

public void doPrev( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//首先获得当前页

String sCurPage = (String)inputData.get("curPage");

int iCurPage = (new Integer(sCurPage)).intValue();

int iIndex = (iCurPage-2)*20;

outputData.put( "pageId", CommonConst.VIEWID_CUSTOMER_DELETE);

//往值域中设置当前位置信息

outputData.put( "pageIndex", new Integer(iIndex) );

return;

}

//到次页

public void doNext( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//首先获得当前页

String sCurPage = (String)inputData.get("curPage");

int iCurPage = (new Integer(sCurPage)).intValue();

int iIndex = iCurPage*20;

outputData.put( "pageId", CommonConst.VIEWID_CUSTOMER_DELETE);

//往值域中设置当前位置信息

outputData.put( "pageIndex", new Integer(iIndex) );

return;

}

//到首页

public void doSpec( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//首先获得指定页码

String sSpecPage = (String)inputData.get("spec");

//获得全部客户信息,并计算出最后一页的位置

Vector allCustomers = (Vector)mySession.getAttribute("customers");

int iMax = allCustomers.size();

int iMaxPage = (int)Math.ceil((double)iMax/20);

int iSpec = (new Integer(sSpecPage)).intValue();

//如果指定页大于全部页码,则跳转到第一页

if ( iSpec > iMaxPage )

{

iSpec = 1;

}

//指定页

outputData.put( "pageId", CommonConst.VIEWID_CUSTOMER_DELETE);

//往值域中设置当前位置信息

outputData.put( "pageIndex", new Integer((iSpec-1)*20) );

return;

}

//修改某条记录

public void doDelete( Hashtable inputData,

Hashtable outputData,

HttpSession mySession )

throws Exception

{

//首先获得要修改的客户ID

String sCustomerId = (String)inputData.get("customerId");

//获得对应的客户的详细信息,然后迁移到客户详细信息修改页面

//调用对应的logic类

LCustomer lCustomer = (LCustomer)GlobalObjectProvider.getLogicService(CommonConst.LOGIC_KEY_CUSTOMER);

//删除对应的记录

lCustomer.deleteCustomerById( sCustomerId );

//然后重新检索,并定位到第一页

Vector vCustomers = lCustomer.getAllCustomer();

//由于需要在页面迁移中使用题库,所以放到session中

mySession.setAttribute( "customers", vCustomers );

//然后迁移到指定页面

outputData.put( "pageId", CommonConst.VIEWID_CUSTOMER_DELETE);

//往值域中设置当前位置信息

outputData.put( "pageIndex", new Integer(0) );

return;

}

}

https://upload.fanwen118.com/wk-img/img100/3785222_8.jpg

5.课程设计总结

MVC模块划分、内容结构如何组织的方法,对一个Web程序设计的影响是很大的,有效的规划可以为Web程序设计增加美感。其它的模块则有一定的联系性。

但是所有的模板其并非是层级关系——即一层一层的点下去,他们可以通过导航栏上的链接转到其它WEB程序设计上,由此可形成一个具有Web程序设计的模式,因此这些模块之间可以实现无顺序关系,却仍能感受到该Web程序设计是一个很条理。美工方面做得还是差了些,以后会多下一番功夫。

我想这次项目的完成对我们有很大的帮助,不仅在JAVA语言的运用上有了提高,对于数据库语言及操作也有了比较全面深刻的了解,比如如何创建一个表,插入相应的字段,给字段添加相关的属性,以及对表进行相关的搜索。在服务器中的.xml文件配置方面也了解到了相应标签的含义以及如何配置,并上传到服务器上。在此次项目中,对有关制作WEB项目的软件比如Tomcat、MyEclipse等软件的运用上也有了小幅的提高。综合一上,这次web项目的制作对我在综合运用方面有了很大的帮助提高。

参考文献:

[1] 沈应逵. Java Web数据库系统应用开发与实例.北京:人民邮电出版社,2009

相关推荐