




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验六 Oracle数据库应用系统班级: 计算机13-1 学号:姓名: 刘炳君 成绩: 一、实验目的(1)掌握通过JDBC连接Oracle数据库的方法;(2)掌握使用JSP对数据库的操纵 ;(3)掌握Oracle数据库应用系统的实现方法。二、实验内容完成简单的药品信息管理系统:在Oracle数据库中创建用户表user、药品类别表category、药品表medicine、销售明细表sellDetail,采用JSP实现用户管理、类别管理、药品管理等功能。 1、创建表、存储过程、触发器2、各功能模块的设计与实现1.登录界面Login.jsp<% p
2、age language="java" pageEncoding="GBK"%><% taglib uri="/struts/tags-bean" prefix="bean" %><% taglib uri="/struts/tags-html" prefix="html" %><% taglib uri="http:/jakarta.
3、/struts/tags-logic" prefix="logic" %><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html:html locale="true"> <head> <title><bean:message key="user.login.title"/></title><style type="te
4、xt/css"><!-bodymargin: 0px;font-size: 12px;background-color: #4C8C1C;.tb1position: relative;top: -355;left: 280;.itbackground-color: #E1FFC1;height: 20px;width: 150px;-></style><script language="javaScript">if(self != top)alert("<bean:message key="use
5、r.login.timeout"/>");top.location = self.location;function login()var form = document.forms"userForm"if(form.elements"username".value = "")alert("<bean:message key="user.username.null"/>");form.elements"username".focus();
6、return;if(form.elements"password".value = "")alert("<bean:message key="user.password.null"/>");form.elements"password".focus();return;form.submit();</script> </head> <body> <html:errors/> <table border="0" w
7、idth="990" height="600" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" align="left" valign="top"> <img src="images/<bean:message key='system.backgroud'/>" b
8、order="0" usemap="#Map"> <html:form action = "login.do" focus="username"> <table border="0" class="tb1"><logic:notEmpty name="error"> <tr> <td colspan="2" align="center"> <be
9、an:message key='user.login.error'/> </td> </tr> </logic:notEmpty> <tr> <td align="right"><bean:message key="user.username"/>:</td> <td><html:text property="username" value="admin" styleClass="i
10、t"/></td> </tr> <tr> <td align="right"><bean:message key="user.password"/>:</td> <td><html:password property="password" value="admin" styleClass="it"/></td> </tr> <tr> <td c
11、olspan="2" align="center" height="30"> <html:button property="lgoin" onclick="login()"> <bean:message key="user.button.login"/> </html:button> <html:reset> <bean:message key="button.reset"/> </h
12、tml:reset> </td> </tr> </table> </html:form> </td> </tr> </table> <map name="Map"><area shape="rect" coords="265,140,323,154" href="<html:rewrite page="/language.do?lan=zh"/>"><area sh
13、ape="rect" coords="335,138,406,153" href="<html:rewrite page="/language.do?lan=en"/>"></map></body></html:html>Main.jsp<% page language="java" pageEncoding="GBK"%><% taglib uri="http:/jakarta.apache.
14、org/struts/tags-bean"prefix="bean"%><% taglib uri="/struts/tags-html"prefix="html"%><% taglib uri="/struts/tags-logic"prefix="logic"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.
15、01 Transitional/EN"><html> <head> <title>'MyJsp.jsp'</title><link rel="stylesheet" type="text/css" href="images/styles.css"> </head> <body> <jsp:forward page="baseData/med.do?command=paging"></
16、jsp:forward> </body></html>Manager.jsp<% page language="java" pageEncoding="GBK"%><% taglib uri="/struts/tags-bean"prefix="bean"%><% taglib uri="/struts/tags-html"prefix=&q
17、uot;html"%><% taglib uri="/struts/tags-logic"prefix="logic"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html><head><title><bean:message key="system.title" /></title><
18、;meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"></head><logic:empty scope="session" name="user"><logic
19、:forward name="login"/></logic:empty><logic:notEmpty scope="session" name="user"><frameset rows="180,*" cols="*" framespacing="0" frameborder="no"border="0"><frame src="top.jsp" name=&qu
20、ot;top" scrolling="NO"><frameset rows="*" cols="223,*" framespacing="0" frameborder="no"border="0"><frame src="left.jsp" name="left"><frame src="baseData/med.do?command=paging" name="
21、;main"></frameset></frameset><noframes><body></body></noframes></logic:notEmpty></html>2药品类别信息管理(1)类别添加页面CategoryAction.javapackage com.lyq.struts.action;import java.util.Date;import java.util.List;import java.util.Map;import javax.servlet.http
22、.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import mons.beanutils.BeanUtils;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.jfree.chart.JFreeChart;import org.jfree.chart.servlet.Se
23、rvletUtilities;import com.lyq.dao.CategoryDao;import com.lyq.persistence.Category;import com.lyq.struts.form.CategoryForm;import com.lyq.util.ChartUtil;/* * 药品类别Action类 * author Li Yong Qiang */public class CategoryAction extends BaseAction /添加或修改类别public ActionForward add(ActionMapping mapping, Act
24、ionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception /获取类别信息CategoryForm cf = (CategoryForm)form;/创建Category对象Category c = new Category();c.setName(cf.getName();c.setDescription(cf.getDescription();c.setCreateTime(new Date();if(cf.getId() != 0)c.setId(cf.getId();Cat
25、egoryDao dao = new CategoryDao();dao.saveOrUpdate(c);return mapping.findForward("paging");/查询类别public ActionForward findAll(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception List list = null;CategoryDao dao = new CategoryDao();
26、list = dao.findByHQL("from Category");request.setAttribute("list", list);return mapping.findForward("findAllSuccess");/编辑类别public ActionForward edit(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception Category
27、Form cf = (CategoryForm)form;/ 判断id是否有效if(cf.getId() > 0)CategoryDao dao = new CategoryDao();Category c = dao.loadCategory(cf.getId();BeanUtils.copyProperties(cf, c);return mapping.findForward("edit");/删除类别public ActionForward delete(ActionMapping mapping, ActionForm form,HttpServletReq
28、uest request, HttpServletResponse response)throws Exception CategoryForm cf = (CategoryForm)form;/ 判断id是否有效if(cf.getId() > 0)CategoryDao dao = new CategoryDao();Category c = dao.loadCategory(cf.getId();dao.delete(c);/删除类别return mapping.findForward("paging");/分页public ActionForward pagin
29、g(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception /获取当前页码String currPage = request.getParameter("currPage");String action = request.getContextPath()+"/baseData/category.do?command=paging"String hql = "from Cate
30、gory"/分页查询Map map = this.getPage(hql, recPerPage, currPage, action,null);/将结果集放到request中request.setAttribute("list", map.get("list");/将结果集放到分页条中request.setAttribute("pagingBar", map.get("bar");return mapping.findForward("findAllSuccess");/ 统计药品类
31、别数量public ActionForward findCategoryAndCound(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 实例化CategoryDao对象CategoryDao dao = new CategoryDao();/ 查询药品类别数量List list = dao.findCategoryAndCount();ChartUtil chartUtil = new ChartUtil();/
32、 创建JFreeChart实例JFreeChart chart = chartUtil.categoryChart(list);if(chart != null)/ 获取图片文件名String fileName = ServletUtilities.saveChartAsJPEG(chart,500,300,request.getSession(); / 获取图片地址String graphURL = request.getContextPath() + "/DisplayChart?filename=" + fileName; / 将图片地址放置到request中requ
33、est.setAttribute("graphURL", graphURL);/ 页面转发return mapping.findForward("categoryGraph");(2)查看类别信息3. 药品信息管理(1)药品添加页面ManagerAction.javapackage com.lyq.struts.action;import java.io.FileOutputStream;import java.io.OutputStream;import java.text.SimpleDateFormat;import java.util.Date;
34、import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import mons.beanutils.BeanUtils;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping
35、;import org.apache.struts.upload.FormFile;import com.lyq.dao.CategoryDao;import com.lyq.dao.MedicineDao;import com.lyq.persistence.Category;import com.lyq.persistence.Medicine;import com.lyq.struts.form.MedicineForm;import com.lyq.util.QueryUtil;import com.lyq.util.StringUtil;/* * 药品Action类 * author
36、 Li Yong Qiang */public class MedicineAction extends BaseAction / 添加药品public ActionForward add(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception Medicine med = null;/ 获取MedicineFormMedicineForm df = (MedicineForm) form;MedicineDao dao =
37、new MedicineDao();if (df.getMedCount() = 0) df.setMedCount(1);med = new Medicine();BeanUtils.copyProperties(med, df);CategoryDao cd = new CategoryDao();Category category = cd.loadCategory(df.getCategoryId();med.setCategory(category);/ 上传图片FormFile photo = df.getPhoto();if (photo != null && p
38、hoto.getFileSize() > 0) String realPath = this.getServlet().getServletContext().getRealPath("/upload");/ 将文件上传至服务器中指定的文件下try String fname = photo.getFileName(); / 获取上传文件名称if (fname.indexOf(".") != -1) / 获取文件的扩展名String endWith = fname.substring(fname.lastIndexOf("."),
39、fname.length();/ 用当前的时间生成文件名称SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");fname = sdf.format(new Date() + endWith;/ 创建写入服务器地址的输出流对象OutputStream out = new FileOutputStream(realPath + "/" + fname); out.write(photo.getFileData();/ 将文件写入到服务器out.flush();out.close()
40、;/ 将文件名称保存到数据库med.setPhotoPath(fname); catch (Exception e) e.printStackTrace();dao.saveOrUpdate(med);return mapping.findForward("addSuccess");/ 添加药品public ActionForward update(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception /
41、 获取MedicineFormMedicineForm df = (MedicineForm) form;MedicineDao dao = new MedicineDao();/ 药品已存在,更新药品数量Medicine med = dao.loadMedicine(df.getId();int medCount = med.getMedCount();med.setMedCount(medCount + df.getMedCount();return mapping.findForward("addSuccess");/ 根据medNo查询药品public Action
42、Forward findMedicineByMedNo(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception / 获取MedicineFormMedicineForm df = (MedicineForm) form;Medicine med = null;/ 查询药品if (df != null && df.getMedNo() != null) MedicineDao dao = new Medicine
43、Dao();med = dao.findMedicineByMedNo(df.getMedNo();/ 如果药品存在,更新数量,否则添加新药if (med != null) BeanUtils.copyProperties(df, med);request.setAttribute("med", "med");return mapping.findForward("medUpdate"); else CategoryDao cd = new CategoryDao();List list = cd.findByHQL("fr
44、om Category");request.setAttribute("cs", list);return mapping.findForward("medSave");/ 分页查询药品信息public ActionForward paging(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 获取页码String currPage = request.getPara
45、meter("currPage");/ 构建action地址String action = request.getContextPath() + "/baseData/med.do?command=paging"/ HQL查询语句String hql = "from Medicine"/ 分页查询,返回Map对象Map map = this.getPage(hql, recPerPage, currPage, action, null);/将结果集放到request中request.setAttribute("list&qu
46、ot;, map.get("list");/将结果集放到分页条中request.setAttribute("pagingBar", map.get("bar");return mapping.findForward("findAllSuccess");/ 查看药品详细信息public ActionForward view(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)th
47、rows Exception String id = request.getParameter("id");Medicine med = null;/ 根据id查询药品信息if (id != null && !"".equals(id) MedicineDao dao = new MedicineDao();med = dao.loadMedicineAndCategory(Integer.parseInt(id);request.setAttribute("med", med);return mapping.find
48、Forward("view");/ 编辑药品信息public ActionForward edit(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 获取MedicineFormMedicineForm df = (MedicineForm) form;Medicine med = null;/ 根据id查询药品if (df.getId() > 0) MedicineDao dao = ne
49、w MedicineDao();med = dao.loadMedicineAndCategory(df.getId();BeanUtils.copyProperties(df, med);df.setCategoryId(med.getCategory().getId();/ 获取类别信息CategoryDao categoryDao = new CategoryDao();List cs = categoryDao.findByHQL("from Category");request.setAttribute("cs", cs);return map
50、ping.findForward("medSave");/ 多条件查询,分页显示结果public ActionForward query(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 获取MedicineFormMedicineForm df = (MedicineForm) form;String currPage = request.getParameter("currPage&
51、quot;);/ 构造查询ActionString action = request.getContextPath() + "/baseData/med.do?command=query"/构造HQL语句及分页条件Map mapQuery = QueryUtil.queryMedicine(df, currPage, action);String hql = (String) mapQuery.get("hql");action = (String) mapQuery.get("action");Object where = (Obj
52、ect) mapQuery.get("where");/ 分页查询Map map = this.getPage(hql, recPerPage, currPage, action, where);/将结果集放到request中request.setAttribute("list", map.get("list");/将结果集放到分页条中request.setAttribute("pagingBar", map.get("bar");return mapping.findForward("
53、;findAllSuccess");/ 模糊查询public ActionForward blurQuery(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 获取关键词String keyWord = request.getParameter("keyWord");/ 获取当前页String currPage = request.getParameter("currPage&
54、quot;);String hql = "from Medicine d "Object where = null;String action = request.getContextPath() + "/baseData/med.do?command=blurQuery"/ 转码if (currPage != null && !currPage.isEmpty() keyWord = StringUtil.encodeZh(keyWord);if (keyWord != null && !keyWord.isEmpty(
55、) action += "&keyWord=" + StringUtil.encodeURL(keyWord);keyWord = "%" + keyWord + "%"hql += " where like ? or d.medNo like ? or d.factoryAdd like ? or d.description like ?"where = new Object keyWord, keyWord, keyWord, keyWord ;/ 分页查询Map map = this.g
56、etPage(hql, recPerPage, currPage, action, where);/将结果集放到request中request.setAttribute("list", map.get("list");/将结果集放到分页条中request.setAttribute("pagingBar", map.get("bar");return mapping.findForward("findAllSuccess");/ 浏览可买的药品public ActionForward canSel
57、lMeds(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / HQL查询条件String hql = "from Medicine d where d.medCount > 0"/ 获取当前页String currPage = request.getParameter("currPage");String action = request.getContextPath()
58、 + "/baseData/med.do?command=canSellMeds"/ 分页查询Map map = this.getPage(hql, recPerPage, currPage, action, null);/将结果集放到request中request.setAttribute("list", map.get("list");/将结果集放到分页条中request.setAttribute("pagingBar", map.get("bar");return mapping.find
59、Forward("canSellMeds");/ 查询库存public ActionForward QueryMedCount(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 获取查询数量String count = request.getParameter("count");/ 获取查询类型(>、<、=)String type = request.getPara
60、meter("type");/ 获取当前页String currPage = request.getParameter("currPage");Object where = null;String hql = "from Medicine d"String action = request.getContextPath() + "/require/require.do?command=blurQuery"if (count != null && type != null) / 构造条件if (type.equals("0") hql = "from Medicine d where d.medCount = ?" e
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 英国罗伯特与学前教育发展史
- 工厂设计答辩结论撰写要点
- 工程项目管理学习资源试题及答案
- 行政管理经济法申诉案例试题及答案
- 社会教育节约用水实施路径
- 2025年工程经济经典例题试题及答案
- 冲刺抢分卷03 备战2025年高考考前仿真模拟卷冲刺抢分卷化学试题03 (辽宁、黑龙江、吉林、内蒙古专用) 含解析
- 生产航天无人机领域装置、海底深水探测动力装置、工业母机直线电机项目可行性研究报告写作模板-备案审批
- 如何优化工程绩效评估试题及答案
- 现代工程经济应用实践试题及答案
- 2025年离婚协议书范本(无争议)
- 第12讲 反比例函数的图象、性质及应用 课件中考数学复习
- 2025中国东方航空技术限公司全球校园招聘高频重点模拟试卷提升(共500题附带答案详解)
- 北森行测测评题库2022
- 生物信息学基础讲座课件
- 卫星互联网应用与挑战
- 《生物医用陶瓷》课件
- 浙江宁波鄞州区市级名校2025届中考生物全真模拟试卷含解析
- 第2课 抗美援朝 课件(共13张)
- 国家电网十八项重大反事故措施
- 院感教学课件
评论
0/150
提交评论