




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、實驗六 Oracle數(shù)據(jù)庫應(yīng)用系統(tǒng)班級: 計算機13-1 學(xué)號:姓名: 劉炳君 成績: 一、實驗?zāi)康模?)掌握通過JDBC連接Oracle數(shù)據(jù)庫的方法;(2)掌握使用JSP對數(shù)據(jù)庫的操縱 ;(3)掌握Oracle數(shù)據(jù)庫應(yīng)用系統(tǒng)的實現(xiàn)方法。二、實驗內(nèi)容完成簡單的藥品信息管理系統(tǒng):在Oracle數(shù)據(jù)庫中創(chuàng)建用戶表user、藥品類別表category、藥品表medicine、銷售明細表sellDetail,采用JSP實現(xiàn)用戶管理、類別管理、藥品管理等功能。 1、創(chuàng)建表、存儲過程、觸發(fā)器2、各功能模塊的設(shè)計與實現(xiàn)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;/創(chuàng)建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 /獲取當(dāng)前頁碼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);/將結(jié)果集放到request中request.setAttribute("list", map.get("list");/將結(jié)果集放到分頁條中request.setAttribute("pagingBar", map.get("bar");return mapping.findForward("findAllSuccess");/ 統(tǒng)計藥品類
31、別數(shù)量public ActionForward findCategoryAndCound(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 實例化CategoryDao對象CategoryDao dao = new CategoryDao();/ 查詢藥品類別數(shù)量List list = dao.findCategoryAndCount();ChartUtil chartUtil = new ChartUtil();/
32、 創(chuàng)建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);/ 頁面轉(zhuǎn)發(fā)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);/ 上傳圖片F(xiàn)ormFile photo = df.getPhoto();if (photo != null && p
38、hoto.getFileSize() > 0) String realPath = this.getServlet().getServletContext().getRealPath("/upload");/ 將文件上傳至服務(wù)器中指定的文件下try String fname = photo.getFileName(); / 獲取上傳文件名稱if (fname.indexOf(".") != -1) / 獲取文件的擴展名String endWith = fname.substring(fname.lastIndexOf("."),
39、fname.length();/ 用當(dāng)前的時間生成文件名稱SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");fname = sdf.format(new Date() + endWith;/ 創(chuàng)建寫入服務(wù)器地址的輸出流對象OutputStream out = new FileOutputStream(realPath + "/" + fname); out.write(photo.getFileData();/ 將文件寫入到服務(wù)器out.flush();out.close()
40、;/ 將文件名稱保存到數(shù)據(jù)庫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();/ 藥品已存在,更新藥品數(shù)量Medicine med = dao.loadMedicine(df.getId();int medCount = med.getMedCount();med.setMedCount(medCount + df.getMedCount();return mapping.findForward("addSuccess");/ 根據(jù)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();/ 如果藥品存在,更新數(shù)量,否則添加新藥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");/ 構(gòu)建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);/將結(jié)果集放到request中request.setAttribute("list&qu
46、ot;, map.get("list");/將結(jié)果集放到分頁條中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;/ 根據(jù)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;/ 根據(jù)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");/ 多條件查詢,分頁顯示結(jié)果public ActionForward query(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 獲取MedicineFormMedicineForm df = (MedicineForm) form;String currPage = request.getParameter("currPage&
51、quot;);/ 構(gòu)造查詢ActionString action = request.getContextPath() + "/baseData/med.do?command=query"/構(gòu)造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);/將結(jié)果集放到request中request.setAttribute("list", map.get("list");/將結(jié)果集放到分頁條中request.setAttribute("pagingBar", map.get("bar");return mapping.findForward("
53、;findAllSuccess");/ 模糊查詢public ActionForward blurQuery(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception / 獲取關(guān)鍵詞String keyWord = request.getParameter("keyWord");/ 獲取當(dāng)前頁String currPage = request.getParameter("currPage&
54、quot;);String hql = "from Medicine d "Object where = null;String action = request.getContextPath() + "/baseData/med.do?command=blurQuery"/ 轉(zhuǎn)碼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);/將結(jié)果集放到request中request.setAttribute("list", map.get("list");/將結(jié)果集放到分頁條中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"/ 獲取當(dāng)前頁String currPage = request.getParameter("currPage");String action = request.getContextPath()
58、 + "/baseData/med.do?command=canSellMeds"/ 分頁查詢Map map = this.getPage(hql, recPerPage, currPage, action, null);/將結(jié)果集放到request中request.setAttribute("list", map.get("list");/將結(jié)果集放到分頁條中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 / 獲取查詢數(shù)量String count = request.getParameter("count");/ 獲取查詢類型(>、<、=)String type = request.getPara
60、meter("type");/ 獲取當(dāng)前頁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) / 構(gòu)造條件if (type.equals("0") hql = "from Medicine d where d.medCount = ?" e
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年微型核反應(yīng)堆及配套產(chǎn)品項目建議書
- 自愿退出合同協(xié)議書
- 舞蹈老師勞動協(xié)議書
- 老人出行租車協(xié)議書
- 訴訟撤訴和解協(xié)議書
- 自助洗車轉(zhuǎn)讓協(xié)議書
- 線上汽車定購協(xié)議書
- 累計貨款結(jié)算協(xié)議書
- 職工補交社保協(xié)議書
- 股權(quán)遠期交割協(xié)議書
- 中考英語情景交際和看圖寫話
- 知道智慧網(wǎng)課《科學(xué)社會主義概論》章節(jié)測試答案
- 2024國有土地房屋買賣合同
- QB/T 2660-2024 化妝水(正式版)
- 《養(yǎng)老護理員》-課件:自然災(zāi)害的應(yīng)對處理知識
- 新思想引領(lǐng)新征程新青年建功新時代 (修改版)
- 跨部門協(xié)調(diào)與部門間合作
- 鋼結(jié)構(gòu)工程施工組織設(shè)計完整版
- 飼料添加劑(全)課件
- 《田間藥效試驗》課件
- 勞務(wù)外包服務(wù)方案(技術(shù)方案)
評論
0/150
提交評論