基于Struts2的供求信息网设计(三)
六,項目功能模塊分析
Struts.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts><package name="hust" extends="struts-default" namespace="/"><!-- 首頁 --><action name="homeaction" class="com.hust.Action.HomeAction"><result name="success">homepage.jsp</result></action><!-- job列表 --><action name="joblistaction" class="com.hust.Action.JobListAction"><result name="success">joblist.jsp</result></action><!-- 發布job消息 --><action name="releasejobaction" class="com.hust.Action.ReleaseJobAction"><!-- action轉發 到action要加type="redirect",且****.action后綴 --><result name="success" type="redirect">joblistaction.action</result><result name="input">joblist.jsp</result></action><!-- lecture列表 --><action name="lecturelistaction" class="com.hust.Action.LectureListAction"><result name="success">lecturelist.jsp</result></action><!-- singlelecture --><action name="showlectureaction" class="com.hust.Action.ShowLectureAction"><result name="success">lecture.jsp</result></action><!-- 發布lecture信息 --><action name="releaselectureaction" class="com.hust.Action.ReleaseLectureAction"><!-- action轉發 到action要加type="redirect",且****.action后綴 --><result name="success" type="redirect">lecturelistaction.action</result><result name="input">releaselecture.jsp</result></action> </package> </struts> 6.1首頁模塊
用戶在瀏覽器端請求地址http://localhost:8080/HustSchool/index.jsp, 但是在index.jsp中重定向homeaction,經過攔截器攔截在Struts.xml配置文件中找到對應的action,執行代碼返回一個字符串,Struts.xml配置文件中的action標簽的result標簽中找到對應的jsp或action
Index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% response.sendRedirect("homeaction.action"); %> Homeaction.java
package com.hust.Action;import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.interceptor.SessionAware;import com.hust.Dao.JobDao; import com.hust.Dao.LectureDao; import com.hust.Dao.RecruitDao; import com.hust.Dao.RentDao; import com.hust.Dao.TutorDao; import com.hust.Dao.TypeDao; import com.hust.tools.MySuperAction;public class HomeAction extends MySuperAction {/*** */private static final long serialVersionUID = 1L;public String execute() throws Exception{//獲取每個類別的信息List<List<String>> allTypeList=new ArrayList<List<String>>();allTypeList.add(TutorDao.GetTitleList());allTypeList.add(JobDao.GetTitleList());allTypeList.add(LectureDao.GetTitleList());allTypeList.add(RecruitDao.GetTitleList());allTypeList.add(RentDao.GetTitleList());request.setAttribute("allTypeList", allTypeList);List<String> TypeList=new ArrayList<String>();TypeList.add("家教信息");TypeList.add("兼職信息");TypeList.add("講座信息");TypeList.add("招聘求職");TypeList.add("房屋租賃"); session.put("TypeList",TypeList);return SUCCESS;}} Action標簽
<action name="homeaction" class="com.hust.Action.HomeAction"><result name="success">homepage.jsp</result></action> homepage.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%@ taglib uri="/struts-tags" prefix="s"%> <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";String mainPage=(String)request.getAttribute("mainPage");if(mainPage==null||mainPage.equals(""))mainPage="main.jsp"; %><html> <head><title>華中科技大學供求信息網</title><base href="<%=basePath%>"> </head> <body ><center><table border="0" width="960" cellspacing="0" cellpadding="0" bgcolor="white" bordercolor="#ffff00"><tr><td colspan="4"><jsp:include page="top.jsp"/></td></tr><tr height="3"><td></td></tr><tr height="611"><td><table width="97%" height="100%" align="center" border="0"><tr><td width="230px" valign="top" align="center"><jsp:include page="left.jsp"/> </td> <td width="690px" align="center" valign="top" bgcolor="#FFFFFF"><jsp:include page="<%=mainPage %>"/></td></tr> </table> </td></tr><tr><td colspan="4" align="center"><jsp:include page="end.jsp"/></td></tr></table> </center> </body> </html> Homeaction.jsp是由top.jsp,left.jsp,main.jsp組成
top.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>頁眉</title><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css">.divbar{text-align:left;width:960px; margin-left:auto; margin-right: auto;background:#0000ff;}.divbar table td{ width:120px; height:30px; color:White; font-size:15px; border-left:solid 1px #ffffff; text-align:center;}.divbar table td:hover{ cursor:pointer;background-color:#00B2EE; }</style></head> <body bgcolor="#F0E68C"><center><table border="0" width="100%" cellspacing="0" cellpadding="0" bordercolor="#ff0000"><!-- 頂部菜單 --><tr height="20" ><td style="text-indent:10" valign="bottom" ><!-- text-indent,將文本首行縮進10像素 --><a href="" style="color:gray">[發布信息]</a><a href="" style="color:gray">[進入后臺]</a></td><td align="right" valign="bottom"><a href="#" style="color:gray" οnclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://localhost:8080/HustSchool');">設為主頁 -</a><a href="javascript:window.external.AddFavorite('http://localhost:8080/HustSchool','華中科技大學供求信息網')" style="color:gray">收藏本頁 -</a><a href="mailto:123@***.com.cn" style="color:gray">聯系我們</a></td></tr><!-- 學校標識 --><tr height="80" ><td colspan="2"><img src="images/hust.png"></td></tr></table> <div class="divbar"> <table cellpadding="10" cellspacing="0" border="0" align="center"><tr><td οnclick="location.href='/HustSchool/homeaction'">首??頁</td><td οnclick="location.href='/'">家教信息</td> <!-- 一個斜杠只是服務器名和端口名,所以要加工程名和action名 --><td οnclick="location.href='/'">跳蚤市場</td><td οnclick="location.href='/HustSchool/joblistaction'" >兼職信息</td><td οnclick="location.href='/HustSchool/lecturelistaction!HustLecture'">講座信息</td><td οnclick="location.href='/'">招聘求職</td><td οnclick="location.href='/'">房屋租賃</td></tr></table></div> </center></body> </html> Left.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.TreeMap" %> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%TreeMap<String,String> searchType=new TreeMap<String,String>();searchType.put("like","模糊");searchType.put("all","全字");request.setAttribute("searchType",searchType); %><html> <head><title>側欄</title><style type="text/css">a:link{color:BLACK;font-size:15px;text-decoration:none;}a:visited{color:BLACK;text-decoration:none;}a:hover{color:blue;text-decoration:underline }a:active{color:blue;}/*激活,紅色*/</style> </head> <body><center><table border="0" width="230" height="100%" cellspacing="0" cellpadding="0" align="center"><tr height="30"><td valign="bottom" style="text-indent:5"><font color="#004790"><b>■日歷</b></font></td></tr> <tr height="1"><td></td></tr><tr height="215"><td valign="top" background="images/leftD.jpg"><jsp:include page="calendar.jsp"/></td></tr><tr height="1"><td></td></tr><tr height="30"><td style="text-indent:5" valign="bottom"><font color="#004790"><b>■信息快速搜索</b></font></td></tr><tr height="1"><td></td></tr><tr height="103"><td align="center" valign="top" background="images/leftS.jpg"><s:form action="" method="post" theme="simple"> <!-- simple主題會是struts標簽的label屬性失效但是提交按鈕不會自動換行 --><table border="0" width="210" height="100%" cellspacing="0" bordercolor="#ff0000"><tr height="10"><td colspan="3"></td></tr><tr> <td width="70" align="right">關鍵詞:</td> <td colspan="2" ><s:textfield name="" value="" size="15" /></td></tr><tr> <td width="70" align="right">條件:</td> <td> <s:select emptyOption="true"list="{'家教信息','尋物啟事','兼職信息','講座信息','招聘信息','房屋租賃'}"headearValue="--請選擇--"headerKey="1" name="type" /></td><td align="left" width="20"><s:submit value="搜索"/></td></tr><tr height="10"><td colspan="3"></td></tr> <tr> <td width="70" align="right"><font size="3">類型:</font></td> <td colspan="2"><s:radio list="#request.searchType"value="%{'like'}"name="searchtype"/> </td></tr><tr height="10"><td colspan="3"></td></tr> </table></s:form> </td></tr><tr bgcolor="#00B48F" height="30"><td style="text-indent:10" ><b><font color="white">▲友情鏈接</font></b> </td></tr><tr height="3"><td></td></tr><tr height="200" > <td align="center"><table width="99%" height="100%" border="0" bgcolor="#E0EEEE"><tr><td align="left"><a href="http://bbs.whnet.edu.cn/" target="_blank">·白云黃鶴BBS</a></td><td align="left"><a href="http://hust.2shoujie.com/" target="_blank">·校園二手街</a></td></tr><tr><td align="left"><a href="http://hub.hust.edu.cn/index.jsp" target="_blank">·HUB系統</a></td><td align="left"><a href="http://student.hust.edu.cn/" target="_blank">·華工在線</a></td></tr> <tr><td align="left"><a href="https://hudbt.hust.edu.cn/index.php" target="_blank">·蝴蝶HUDBT</a></td><td align="left"><a href="http://xsyj.hust.edu.cn/" target="_blank">·數字校史館</a></td></tr> <tr><td align="left"><a href="http://www.hustonline.net/" target="_blank">·華中大在線</a></td><td align="left"><a href="http://aco.hust.edu.cn/" target="_blank">·學術委員會</a></td></tr><tr><td align="left"><a href="http://sunshine.hust.edu.cn/" target="_blank">·喻園晨光</a></td><td align="left"><a href="http://ecard.hust.edu.cn/" target="_blank">·校園卡</a></td></tr> <tr><td align="left"><a href="Course.html" target="_blank">·本科教學</a></td><td align="left"><a href="http://www.tjmu.edu.cn/" target="_blank">·同濟醫學院</a></td></tr> </table> </td> </tr><tr height="100"><td></td></tr></table> </center> </body> </html> Main.jsp運用了Struts的標簽,在jsp頁面減少使用了java代碼
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>主顯示區</title><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><% List<String> typelist=(List<String>)session.getAttribute("TypeList"); int i=0; %><center> <!-- 獲取request的alltypelist,并賦予新的變量 --> <s:set name="allTypeList" value="#request.allTypeList"></s:set> <img alt="photo" src="images/photo.gif"><table border="0" width="690" cellspacing="3" cellpadding="0"><tr height="35"><td colspan="2" style="text-indent:5" valign="bottom"><font color="#004790"><b>■最新信息</b>『免費專區』</font></td></tr> <s:iterator status="allTypeStatus" value="allTypeList" id="SingleTypeList"><s:if test="#allTypeStatus.odd"><tr></s:if><td align="center"><table border="0" cellspacing="0" cellpadding="0" width="332" height="160" rules="none" style=" border: 2px solid #2cb7fe;" ><s:iterator status="oneStatus" value="SingleTypeList" id="SingleTitle"><s:if test="#oneStatus.index==0"><tr bgcolor="#00B48F" height="30"><td style="text-indent:10"><b><font color="white">▲<%=typelist.get(i) %></font></b></td> <td align="right"><a href="">more...</a>??</td><% i++; %> </tr></s:if><tr bgcolor="#FAFCF5"><td style="text-indent:3" colspan="2"><a href=""><font size="2px">★<s:property value="SingleTitle"/>...</font></a></td></tr> </s:iterator></table></td><s:if test="#allStatus.even"></tr></s:if></s:iterator> </table></center></body> </html> 結果圖:
Bug分析:
由于時間緊,完成了3個模塊,信息快速搜索欄的后臺處理代碼沒來得及寫
6.2兼職信息模塊
顯示兼職信息功能:
點擊上面“兼職信息”,會跳轉到http://localhost:8080/HustSchool/joblistaction,會跳轉到joslistaction,JobListAction中獲取lecture表中的講座信息,并且分頁顯示
JobListAction.java
package com.hust.Action;import java.util.List;import com.hust.tools.PageQueryDao; import com.hust.Bean.JobBean; import com.hust.Bean.JobBean; import com.hust.Dao.JobDao; import com.hust.tools.MySuperAction;public class JobListAction extends MySuperAction {/*** */private static final long serialVersionUID = 1L;public String execute(){//JobDao jobdao=new JobDao();//List<JobBean> joblist=jobdao.GetJobList(); int currpage=1;if(request.getParameter("page")!=null){currpage=Integer.parseInt(request.getParameter("page"));}PageQueryDao pagedao=new PageQueryDao();List<JobBean> joblist=pagedao.getJobPageList(currpage);//查詢當前頁記錄int pages; //計算查詢總頁數String sql="select count(*) from job";int count=pagedao.FindCounts(sql);if(count%JobBean.PAGE_SIZE==0){pages=count/JobBean.PAGE_SIZE;}else{pages=count/JobBean.PAGE_SIZE+1;}StringBuffer sb=new StringBuffer();sb.append("<a href='joblistaction?page=1'>首頁</a>");sb.append(" ");//構建分頁條for(int i=1;i<=pages;i++){if(i==currpage){sb.append("『" + i + "』");}else{sb.append("<a href='joblistaction?page="+i+"'>"+i+"</a>");}sb.append(" ");}sb.append("<a href='joblistaction?page="+pages+"'>尾頁</a>");request.setAttribute("joblist", joblist); request.setAttribute("bar", sb.toString());return SUCCESS;} }
這部分為了美觀學習了很多CSS的知識,大多時間都換在了修改樣式外觀上了。
發布兼職信息功能:
點擊“我要發布”,可以進入發布兼職信息頁面releasejob.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>華中科技大學兼職工作</title><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css"> .jzgs{ border-top-width: 2px;border-right-width: 2px;border-bottom-width: 2px;border-left-width: 2px;border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-color: #C1E9E8;border-bottom-color: #C1E9E8;border-left-color: #C1E9E8;height: 290px;width:270px }.jzgs td{font-size:13px;height:22px;padding-left:20px;} a:link{color:#E066FF;text-decoration:none;}a:hover{color:#EE9A00;text-decoration:underline;} a:active{color:#000000;text-decoration:none;} .release:hover{text-decoration:none;} </style></head><body><center><!-- 獲得request的joblist和分頁條 --><s:set name="joblist" value="#request.joblist"></s:set><table border="0" width="960" cellspacing="0" cellpadding="0" bordercolor="#fff922" bgColor="#ffffff"><tr><td colspan="4"><jsp:include page="top.jsp"/></td> </tr><tr height="3"><td colspan="4"></td></tr><tr height="27" bgcolor="#F0FFFF"><td colspan="2"><span style="text-indent:15px;color:#FF8C00">?當前位置:<a href="joblistaction">兼職工作</a>>>【發布信息】</span></td><td colspan="1" align="right"><a href="releasejob.jsp" class="release"><font color="bule">【我要發布】</font></a></td><td width="15" ></td></tr><tr height="700" ><td width="15px" ></td><td width="270" valign="top" align="center"><div class="jzgs"><table width="270" border="0"><tr height="30px"><td background="images/jzgs.png"><font color=" #007B7B"><b>兼職故事</b></font></td> </tr><tr><td align="left" >·<a href="jzgs01.jsp" >“兼職牛人”一天最多打5份工</a></td></tr><tr><td align="left" >·<a href="jzgs02.jsp" >自強姐姐大學3年兼職供弟弟讀書</a></td></tr><tr><td align="left" >·<a href="jzgs03.jsp" >兼職微商故事</a></td></tr> <tr><td align="left" >·<a href="jzgs04.jsp" >大學生實習或兼職,暑假收獲滿滿</a></td></tr> <tr><td align="left" >·<a href="jzgs05.jsp" >七夕情人節兼職賣花攻略大全</a></td></tr> <tr><td align="left" >·<a href="jzgs06.jsp" >兼職打工 體味生活艱辛</a></td></tr> <tr><td align="left" >·<a href="jzgs07.jsp" >90后大學生暑期在街頭兼職</a></td></tr><tr><td align="left" >·<a href="jzgs08.jsp" >大學生暑期兼職經驗比賺錢重要</a></td></tr> </table></div> <br><div class="jzgs"><table width="270" border="0"><tr height="30px"><td background="images/jzgs.png"><font color=" #007B7B"><b>兼職專題</b></font></td> </tr><tr><td align="left" >·<a href="" >周末可以做的兼職有哪些</a></td></tr><tr><td align="left" >·<a href="" >大學生求職注意事項</a></td></tr><tr><td align="left" >·<a href="" >網上兼職靠譜嗎?</a></td></tr> <tr><td align="left" >·<a href="" >盤點最常見的網上兼職騙局</a></td></tr> <tr><td align="left" >·<a href="" >正規招聘兼職的網站有哪些?</a></td></tr> <tr><td align="left" >·<a href="" >網上兼職工作需要注意哪些方面?</a></td></tr> <tr><td align="left" >·<a href="" >女大學生適合的幾種兼職</a></td></tr> <tr><td align="left" >·<a href="" >大學生在家兼職有哪些</a></td></tr><tr><td align="left" >·<a href="" >網絡求兼職還請擦亮雙眼</a></td></tr> </table></div> </td><td width="650" valign="top"> <jsp:include page="release.jsp"></jsp:include> <!-- 包含發布job頁面 --> </td><td width="15" ></td></tr><tr><td align="center" colspan="4"><jsp:include page="end.jsp"/></td></tr></table> </center></body> </html>
releasejob.jsp主要板塊是包含release.jsp
release.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>發布信息</title><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css">.one{width:650px;height:20px;}.two{width:650px;height:400px; }.three{width:650px;height:27px;}.table1{font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;width:95%;height:95%; border-collapse:collapse;}.table1 td, .table1 th{font-size:1em; border:1px solid #AEEEEE;padding:3px 7px 2px 7px;}.table1 th{font-size:1.1em;text-align:left;background-color:#C6E2FF;color:#FFF;}.table1 tr.alt td{ color:#000;background-color:#EAF2D3;}.qq{width:100px; }</style></head><body><center><div class="one" style="background:url(images/bg-top.jpg)"></div> <div class="two" style="background:url(images/bg-mid.jpg)"><s:form action="releasejobaction" theme="simple"><table border="0" bordercolor="#ff0000" class="table1"><tr><th class="qq"><b>標?????題:</b></th><th><s:textfield name="title" style="font-size:18px;width:200px;height:30px;"></s:textfield></th></tr><tr ><td class="qq"><b>公司名稱:</b></td><td ><s:textfield name="company" style="font-size:18px;width:200px;height:30px;" ></s:textfield></td></tr ><tr class="alt"><td class="qq"><b>工作內容:</b></td><td><s:textfield name="content" style="font-size:18px;width:400px;height:30px;"></s:textfield></td> </tr><tr><td class="qq"><b>工作時間:</b></td><td><s:textfield name="time" style="font-size:18px;width:200px;height:30px;"></s:textfield></td> </tr><tr class="alt"><td class="qq"><b>工作地址:</b></td><td><s:textfield name="address" style="font-size:18px;width:400px;height:30px;"></s:textfield></td> </tr><tr ><td class="qq"><b>工資薪酬:</b></td><td><s:textfield name="pay" style="font-size:18px;width:200px;height:30px;"></s:textfield></td> </tr><tr class="alt"><td class="qq"><b>備?????注:</b></td><td><s:textfield name="remark" style="font-size:18px;width:500px;height:30px;"></s:textfield></td> </tr><tr ><td class="qq"><b>聯?系?人?:</b></td><td><s:textfield name="linkman" style="font-size:18px;width:200px;height:30px;"></s:textfield></td> </tr><tr class="alt"><td class="qq"><b>聯系電話:</b></td><td><s:textfield name="phone" style="font-size:18px;width:200px;height:30px;"></s:textfield></td> </tr><tr><td colspan="2" align="center"><s:submit value="確認發布" style="background:url(images/submit.png) no-repeat;width:100px; height:35px;"></s:submit></td></tr></table> </s:form></div> <div class="three" style="background:url(images/bg-bot.jpg)"></div> </center></body> </html> 結果圖:
當點擊“確認發布”后,表單會提交到releasejobaction,在此action中將表單添加到數據庫,并更新兼職信息的頁面
package com.hust.Action;import java.util.Date;import com.hust.Dao.JobDao; import com.hust.tools.DateToString; import com.hust.tools.MySuperAction; import com.hust.tools.PageQueryDao;public class ReleaseJobAction extends MySuperAction {/*** */private static final long serialVersionUID = 1L;private String title;private String company;private String content;private String time;private String address;private String pay;private String remark;private String linkman;private String phone;public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getCompany() {return company;}public void setCompany(String company) {this.company = company;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public String getTime() {return time;}public void setTime(String time) {this.time = time;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public String getPay() {return pay;}public void setPay(String pay) {this.pay = pay;}public String getRemark() {return remark;}public void setRemark(String remark) {this.remark = remark;}public String getLinkman() {return linkman;}public void setLinkman(String linkman) {this.linkman = linkman;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}public String execute(){Date date=new Date();String datestr=DateToString.dateTimeChange(date);//發布日期PageQueryDao pagedao=new PageQueryDao();int totalrecords=pagedao.FindCounts("select count(*) from job");//目前總記錄數int id=totalrecords+1;String[] ss={String.valueOf(id),title,company,content,time,address,pay,remark,linkman,phone,datestr};JobDao jobdao=new JobDao();boolean b=jobdao.InsertJob(ss);if(b){//把msg傳給jobjistactionreturn SUCCESS; }else{return INPUT; }}} 發布成功之后:
點擊左側欄的“兼職故事”或者“兼職專題”結果圖:
6.3講座信息模塊
點擊標題欄“講座信息”進入講座信息模塊,這個模塊主要有“華科大講座”,“武漢講座”,“公益講座”,“講座活動”,“中國講座網”這5個模塊,但是目前只做了“華科大講座”和“武漢講座”
這二者的區分是在lecture表中用“0”,“1”標志區分的
點擊標題欄“講座信息”的鏈接是:http://localhost:8080/HustSchool/lecturelistaction!HustLecture, 先訪問lecturelistaction中的HustLecture方法
<!-- lecture列表 --><action name="lecturelistaction" class="com.hust.Action.LectureListAction"><result name="success">lecturelist.jsp</result></action> LectureListAction.java中只有兩個方法HustLecture,WuhanLecture,這兩個方法
package com.hust.Action;import java.util.List;import com.hust.Bean.JobBean; import com.hust.Bean.LectureBean; import com.hust.tools.MySuperAction; import com.hust.tools.PageQueryDao;public class LectureListAction extends MySuperAction{/*** */private static final long serialVersionUID = 1L;//查詢華科講座public String HustLecture(){int currpage=1;if(request.getParameter("page")!=null){currpage=Integer.parseInt(request.getParameter("page"));}PageQueryDao pagedao=new PageQueryDao();String sql="select * from lecture where Sign=1 order by Id desc limit ?,? ";List<LectureBean> lecturelist=pagedao.getLecturePageList(currpage,sql);//查詢當前頁記錄int pages; //計算查詢總頁數String sql1="select count(*) from lecture where Sign=1";int count=pagedao.FindCounts(sql1);if(count%LectureBean.PAGE_SIZE==0){pages=count/LectureBean.PAGE_SIZE;}else{pages=count/LectureBean.PAGE_SIZE+1;}StringBuffer sb=new StringBuffer();sb.append("<a href='lecturelistaction!HustLecture?page=1'>首頁</a>");sb.append(" ");//構建分頁條for(int i=1;i<=pages;i++){if(i==currpage){sb.append("『" + i + "』");}else{sb.append("<a href='lecturelistaction!HustLecture?page="+i+"'>"+i+"</a>");}sb.append(" ");}sb.append("<a href='lecturelistaction!HustLecture?page="+pages+"'>尾頁</a>");request.setAttribute("lecturelist", lecturelist); request.setAttribute("bar", sb.toString());return SUCCESS; }//查詢武漢講座public String WuhanLecture(){int currpage=1;if(request.getParameter("page")!=null){currpage=Integer.parseInt(request.getParameter("page"));}PageQueryDao pagedao=new PageQueryDao();String sql="select * from lecture where Sign=0 or Sign=1 order by Id desc limit ?,? ";List<LectureBean> lecturelist=pagedao.getLecturePageList(currpage,sql);//查詢當前頁記錄int pages; //計算查詢總頁數String sql1="select count(*) from lecture";int count=pagedao.FindCounts(sql1);if(count%LectureBean.PAGE_SIZE==0){pages=count/LectureBean.PAGE_SIZE;}else{pages=count/LectureBean.PAGE_SIZE+1;}StringBuffer sb=new StringBuffer();sb.append("<a href='lecturelistaction!WuhanLecture?page=1'>首頁</a>");sb.append(" ");//構建分頁條for(int i=1;i<=pages;i++){if(i==currpage){sb.append("『" + i + "』");}else{sb.append("<a href='lecturelistaction!WuhanLecture?page="+i+"'>"+i+"</a>");}sb.append(" ");}sb.append("<a href='lecturelistaction!WuhanLecture?page="+pages+"'>尾頁</a>");request.setAttribute("lecturelist", lecturelist); request.setAttribute("bar", sb.toString());return SUCCESS; }public String execute(){HustLecture();return SUCCESS;} } Lecturelist.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>華中科技大學講座信息</title><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css"> .box{border-radius: 10px;margin-top:20px;width:270px;height:270px;border: 2px solid #ccc; }.box .head {font-size:20px;color:#E97F25; font-weight:bold;} .box .head1{padding-top:10px;padding-left:20px;text-align:left;} .box .tips{font-size: 15px;padding: 5px;text-align:left;text-indent: 24px;color: #666; }.box7{margin: 20px auto;width: 600px;min-height: 150px;padding: 10px;position:relative;background: -webkit-gradient(linear, 0% 20%, 0% 92%, from(#fff), to(#FFF8DC), color-stop(.1,#fff));border-top: 1px solid #ccc;border-right: 1px solid #ccc;border-left: 1px solid #ccc;-webkit-box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.2) ; }.box7:before{content: '';position:absolute;width: 130px;height: 30px;border-left: 1px dashed rgba(0, 0, 0, 0.1);border-right: 1px dashed rgba(0, 0, 0, 0.1);background: -webkit-gradient(linear, 555% 20%, 0% 92%, from(rgba(0, 0, 0, 0.1)), to(rgba(0, 0, 0, 0.0)), color-stop(.1,rgba(0, 0, 0, 0.2)));-webkit-box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.2);-webkit-transform:translate(-50px,10px)skew(10deg,10deg)rotate(-50deg) } .box7:after{content: '';position:absolute;right:0;bottom:0;width: 130px;height: 30px;background: -webkit-gradient(linear, 555% 20%, 0% 92%, from(rgba(0, 0, 0, 0.1)), to(rgba(0, 0, 0, 0.0)), color-stop(.1,rgba(0, 0, 0, 0.2)));border-left: 1px dashed rgba(0, 0, 0, 0.1);border-right: 1px dashed rgba(0, 0, 0, 0.1);-webkit-box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.2);-webkit-transform: translate(50px,-20px)skew(10deg,10deg)rotate(-50deg) }.box7:hover{-webkit-box-shadow: 3px 3px 10px #FFF8DC;box-shadow: 3px 3px 10px #FFF8DC ;}a:link{color:blue;text-decoration:none;}a:visited{color:blue;text-decoration:none;}</style></head><body><center><!-- 獲得request的joblist和分頁條 --><s:set name="lecturelist" value="#request.lecturelist"></s:set><% String bar=(String)request.getAttribute("bar"); %><table border="0" width="960" cellspacing="0" cellpadding="0" bordercolor="#fff922" bgColor="#ffffff"><tr><td colspan="4"><jsp:include page="lecturetop.jsp"/></td> </tr><tr height="25"><td colspan="3" align="right"><a href="releaselecture.jsp">【我要發布】</a>?</td></tr><tr height="650" ><td width="15px" height="100%" rowspan="2"></td> <td width="600" valign="top"> <table width="600" align="left" border="0"> <s:iterator value="lecturelist" id="singlelecture" status="st"><!--<s:set name="job" value="singlejob"></s:set> 把單個工作對象賦值新變量 --><tr> <td ><div class="box7" > <table width="100%" height="100" align="center" border="0" bordercolor="#0000ff"> <tr> <td align="left" ><a href="showlectureaction?id=<s:property value='#singlelecture.id'/>"><b><s:property value="#singlelecture.title"/></b></a></td> </tr><tr> <td align="left" ><font size="2">時間:<s:property value="#singlelecture.time"/></font></td> </tr> <tr> <td align="left" ><font size="2">地點:<s:property value="#singlelecture.address"/></font></td> </tr> <tr> <td align="left" ><font size="2">主講:<s:property value="#singlelecture.speaker"/></font></td> </tr> </table></div></td> </tr> </s:iterator> </table> </td><td width="330" valign="top" align="center" rowspan="2"><div class="box"><div class="head1" ><span class="head">柯柯說</span><div style="clear:both"> </div></div><div class="tips"><p >本網站旨在打造講座信息聚合與分享平臺。講座信息由柯柯值班編輯更新。歡迎向我們提供講座信息,聯系郵箱:M201571885@hust.edu.cn(柯柯郵箱)</p></div></div><br><div class="box"><div class="head1"><span class="head">微信訂閱</span><div style="clear:both;"> </div></div><div class="weixin" style="margin-top:20px"> <img src="images/weixin.png"> </div></div></td> <td width="15" rowspan="2"></td></tr><tr><td align="center" ><%=bar %></td></tr><tr><td align="center" colspan="4"><jsp:include page="end.jsp"/></td></tr></table> </center></body> </html> 結果圖:
查看講座詳細信息:
對每一個講座都可以點擊鏈接進入詳細信息頁面
當點擊鏈接時請求提交到showlectureaction http://localhost:8080/HustSchool/showlectureaction?id=10, 把每個講座的Id傳給showlectureaction,在action中根據Id查詢數據庫
ShowLectureAction.java
package com.hust.Action;import com.hust.Bean.LectureBean; import com.hust.Dao.LectureDao; import com.hust.tools.MySuperAction;public class ShowLectureAction extends MySuperAction{/*** */private static final long serialVersionUID = 1L;public String execute(){int id=Integer.valueOf(request.getParameter("id"));//獲得講座的id,查詢整個講座的信息System.out.println(id);LectureDao lecturedao=new LectureDao();LectureBean lecture=lecturedao.getLecture(id);request.setAttribute("lecture", lecture);return SUCCESS;}} 處理完成后返回到lecture.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>華中科技大學講座信息</title><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css">.ss{border: 2px solid #2cb7fe;border-radius: 10px; }.box{border-radius: 10px;margin-top:20px;width:270px;height:270px;border: 2px solid #ccc; }.box .head {font-size:20px;color:#E97F25; font-weight:bold;} .box .head1{padding-top:10px;padding-left:20px;text-align:left;} .box .tips{font-size: 15px;padding: 5px;text-align:left;text-indent: 24px;color: #666; } .box15{margin: 40px auto;width: 600px;min-height: 330px;padding: 10px;position:relative;background: -webkit-gradient(linear, 100% 100%, 50% 10%, from(#fff), to(#f3f3f3), color-stop(.1,#fff));border: 1px solid #ccc;-webkit-box-shadow: 1px 1px 4px rgba(0,0,0, 0.1);-webkit-border-bottom-right-radius: 60px 5px;}.box15:before{content: '';width: 98%;z-index:-1;height: 100%;padding: 0 0 1px 0;position: absolute;bottom:0; right:0;background: -webkit-gradient(linear, 0% 20%, 0% 92%, from(#fff), to(#f9f9f9), color-stop(.1,#fff));border: 1px solid #ccc;-webkit-box-shadow: 1px 1px 8px rgba(0,0,0, 0.1);-webkit-border-bottom-right-radius: 60px 5px;-webkit-transform: skew(2deg,2deg)translate(3px,8px) } .box15:after{content: '';width: 98%;z-index:-1;height: 98%;padding: 0 0 1px 0;position: absolute;bottom:0; right:0;background: -webkit-gradient(linear, 0% 20%, 0% 100%, from(#f3f3f3), to(#f6f6f6), color-stop(.1,#fff));border: 1px solid #ccc;-webkit-box-shadow: 0px 0px 8px rgba(0,0,0, 0.1);-webkit-transform: skew(2deg,2deg)translate(-1px,2px) }.box15_ribbon{position:absolute;top:0; left: 0;width: 130px;height: 40px;background: -webkit-gradient(linear, 555% 20%, 0% 92%, from(rgba(0, 0, 0, 0.1)), to(rgba(0, 0, 0, 0.0)), color-stop(.1,rgba(0, 0, 0, 0.2)));border-left: 1px dashed rgba(0, 0, 0, 0.1);border-right: 1px dashed rgba(0, 0, 0, 0.1);-webkit-box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.2);-webkit-transform: rotate(-30deg) skew(0,0) translate(-30px,-20px); }.title{width:100%;height:50px;padding-top:10px;text-align:center;font-size:23px;font-weight:bold;}.time{width:100%;height:30px;text-align:left;font-size:14px;}.place{width:100%;height:30px;text-align:left;font-size:14px;}.person{width:100%;height:30px;text-align:left;font-size:14px;}.introduce{width:100%;height:100px;text-align:left;font-size:14px;}</style></head><body><center><!-- 獲得request的joblist和分頁條 --><s:set name="lecturelist" value="#request.lecturelist"></s:set><% String bar=(String)request.getAttribute("bar"); %><table border="0" width="960" cellspacing="0" cellpadding="0" bordercolor="#fff922" bgColor="#ffffff"><tr><td colspan="4"><jsp:include page="lecturetop.jsp"/></td> </tr><tr height="25"><td colspan="2" align="left">◎當前位置:<a href="lecturelistaction!HustLecture">華科講座</a>>>【發布講座】</td> </tr><tr height="650" ><td width="15px" height="100%" rowspan="2"></td> <td width="600" valign="top"><s:set name="singlelecture" value="#request.lecture" ></s:set><div class="box15" > <div class="title"><s:property value="#singlelecture.title"/></div> <hr> <div class="time"><b>時間:</b><s:property value="#singlelecture.time"/></div> <div class="place"><b>地點:</b><s:property value="#singlelecture.address"/></div> <div class="person"><b>主講:</b><s:property value="#singlelecture.speaker"/></div> <div class="introduce"><b>詳細信息:</b><br>??<s:property value="#singlelecture.introduce"/></div> <div class="box15_ribbon"></div> </div> </td><td width="330" valign="top" align="center" ><div class="box"><div class="head1" ><span class="head">柯柯說</span><div style="clear:both"> </div></div><div class="tips"><p >本網站旨在打造講座信息聚合與分享平臺。講座信息由柯柯值班編輯更新。歡迎向我們提供講座信息,聯系郵箱:M201571885@hust.edu.cn(柯柯郵箱)</p></div></div><br><div class="box"><div class="head1"><span class="head">微信訂閱</span><div style="clear:both;"> </div></div><div class="weixin" style="margin-top:20px"> <img src="images/weixin.png"> </div></div></td> <td width="15" ></td></tr><tr><td align="center" colspan="4"><jsp:include page="end.jsp"/></td></tr></table> </center></body> </html> 結果圖:
發布講座信息:
點擊“我要發布”會今日發布講座信息頁面
releaselecture.jsp
點擊“確認發布”表單會提交到releaselectureaction,在此action中會把此記錄插入到lecture數據表中,并返回到講座信息頁面
ReleaseLectureAction.java
package com.hust.Action;import java.util.Date;import com.hust.Dao.LectureDao; import com.hust.tools.DateToString; import com.hust.tools.MySuperAction; import com.hust.tools.PageQueryDao;public class ReleaseLectureAction extends MySuperAction{private String title;private String time;private String address;private String speaker;private String introduce;public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getTime() {return time;}public void setTime(String time) {this.time = time;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public String getSpeaker() {return speaker;}public void setSpeaker(String speaker) {this.speaker = speaker;}public String getIntroduce() {return introduce;}public void setIntroduce(String introduce) {this.introduce = introduce;}public String execute(){PageQueryDao pagedao=new PageQueryDao();int id=pagedao.FindCounts("select count(*) from lecture")+1;Date date=new Date();String datestr=DateToString.dateTimeChange(date);//發布日期String sign=null;String params[]={String.valueOf(id),title,speaker,introduce,time,address,sign,datestr};boolean b=(new LectureDao()).InsertLecture(params);System.out.println(b);if(b)return SUCCESS;elsereturn INPUT;}}
<!-- 發布lecture信息 --><action name="releaselectureaction" class="com.hust.Action.ReleaseLectureAction"><!-- action轉發 到action要加type="redirect",且****.action后綴 --><result name="success" type="redirect">lecturelistaction.action</result><result name="input">releaselecture.jsp</result></action>
總結
以上是生活随笔為你收集整理的基于Struts2的供求信息网设计(三)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Struts2的供求信息网设计(二)
- 下一篇: Java日历