- 浏览: 144977 次
- 性别:
- 来自: 南宁
-
文章分类
- 全部博客 (137)
- J2SE API基础 (19)
- JAVA Structure/Algorithm (1)
- 设计模式及UML(pd/rose) (11)
- SSH (32)
- JPA/EJB/JSF (0)
- Jsp/Servlet (1)
- XML (0)
- DWR/Dojo/JQuery(Ajax) (1)
- Js/css/HTML (3)
- Java报表开发 (0)
- 网络协议及认证加密算法 (2)
- Java多线程网络编程 (1)
- Lucence (0)
- Oracle Developer (5)
- Oracle DBA (3)
- mysql/SQLServer/DB2 (5)
- Weblogic配置/调试 (0)
- Tomcat/JBoss/Websphere (10)
- Linux/Unix操作部署及shell编程 (9)
- C/C++编程 (4)
- 系统分析 (0)
- 项目管理(CVS&风险控制) (0)
- JUnit单元和J2EE集成测试 (2)
- 软设/招聘 (6)
- IT English (8)
- Mathematics/Data Mining (1)
- Android开发爱好 (1)
- Flash制作爱好 (0)
- Professional wisdom (4)
- 序言 (1)
- 聊天记录 (0)
- 理想 (3)
- 承诺 (0)
- oifuslfjsldkj_chatrecord (1)
最新评论
-
blues1021:
dafeiwudi 写道什么叫外频和陪频啊?一般电脑都显示主频 ...
计算机组成原理和结构-时钟周期、机器周期、总线周期、指令周期含义和关系 -
dafeiwudi:
什么叫外频和陪频啊?一般电脑都显示主频,它不表示运算速递,我们 ...
计算机组成原理和结构-时钟周期、机器周期、总线周期、指令周期含义和关系
一、在.jsp中用form传入参数:
<html:form action="/stuUser?method=findCourse">
<table border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#afdf69" width="100%">
<tr>
<td height="28" colspan="4" bordercolor="#FFFFFF" bgcolor="#FFFFFF"><span > 请输入搜索条件:
</span></td>
</tr>
<tr>
<td height="28" bordercolor="#FFFFFF" bgcolor="#FFFFFF" align="center">课程类型:
<html:select property="courseType">
<html:option value=""></html:option>
<html:option value="校选人文">校选人文</html:option>
<html:option value="校选自然">校选自然</html:option>
</html:select>
</td>
<td height="24" bordercolor="#FFFFFF" bgcolor="#FFFFFF" align="center">有无余量:
<html:select property="left">
<html:option value=""></html:option>
<html:option value="有">有</html:option>
<html:option value="无">无</html:option>
</html:select>
</td>
<td>上课时间 : <html:select property="week">
<html:option value=""></html:option>
<html:option value="周一">周一</html:option>
<html:option value="周二">周二</html:option>
<html:option value="周三">周三</html:option>
<html:option value="周四">周四</html:option>
<html:option value="周五">周五</html:option>
<html:option value="周六">周六</html:option>
<html:option value="周日">周日</html:option>
</html:select>
<html:select property="time">
<html:option value=""></html:option>
<html:option value="第1,2,3节">第1,2,3节</html:option>
<html:option value="第4,5节">第4,5节</html:option>
<html:option value="第6,7,8节">第6,7,8节</html:option>
<html:option value="第10,11,12节">第10,11,12节</html:option>
</html:select>
</td>
<td height="24" bordercolor="#FFFFFF" bgcolor="#FFFFFF" align="center"><html:submit value="搜索"/></td>
</tr>
</table>
</html:form>
二、在Action类中读取参数调用dao操作数据库方法或业务逻辑处理:
public ActionForward findCourse(ActionMapping mapping,ActionForm form,//用form作为一个传递参数set.
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm courseForm = (DynaActionForm) form;
String courseType = courseForm.getString("courseType");
String left = courseForm.getString("left");
String week = courseForm.getString("week");
String time = courseForm.getString("time");
Map<String,String> map = new HashMap<String,String>();
map.put("courseType", courseType);
map.put("left", left);
map.put("week", week);
map.put("time", time);
List<Course> list = courseDao.findBySearch(map)
;//调用点,为dao类方法
Iterator it = list.iterator();
int number = 0;
while(it.hasNext()){
it.next();
number++;
}
request.setAttribute("list", list);//和后面的迭代设置list
request.setAttribute("number", number);
return findSch(mapping, form, request, response)
;//调用点,为action类中方法
}
三、findBySearch在dao类中处理
public List<Course> findBySearch(Map<String,String> map) {///////////根据map中的条件查找
List<Course> list=null;
String courseType=map.get("courseType");
String remain = map.get("left");
String week = map.get("week");
String time = map.get("time");
if(!courseType.equals("")){
String sql="FROM Course WHERE ";
sql += " courseType ="+"'"+courseType+"'";
if(remain.equals("")||remain.equals("有")){//courseType不为空,remain不为空
sql += " AND remain > 0";
}
if(remain.equals("无")){
sql += " AND remain = 0";
}
if(!week.equals("")){
sql += " AND week ="+"'"+week+"'";
}
if(!time.equals("")){
sql += " AND time ="+"'"+time+"'";
}
list = getHibernateTemplate().find(sql);
return list;
}
if(courseType.equals("")){
String sql="FROM Course WHERE courseType IN ('校选人文','校选自然') ";
if(remain.equals("")||remain.equals("有")){////////////////courseType不为空,remain不为空
sql += " AND remain > 0";
}else if(remain.equals("无")){
sql += " AND remain = 0";
}
if(!week.equals("")){
sql += " AND week ="+"'"+week+"'";
}
if(!time.equals("")){
sql += " AND time ="+"'"+time+"'";
}
list = getHibernateTemplate().find(sql);
return list;
}
else{
list=list = getHibernateTemplate().find("FROM Course");
return list;
}
}
四、 在同一个Action类中调用处理:
public ActionForward findSch
(ActionMapping mapping, ActionForm form,///////找出可选的和已选的校选课
HttpServletRequest request, HttpServletResponse response) {
int stuId = (Integer)request.getSession().getAttribute("loginId");/////////学生序号
Map map = stuUserDao.findSchCourse();
//dao类调用点
List<Course> list = (List)map.get("list");//////////////////////查询学生可选的校选课程
int number = (Integer)map.get("number");
List<Course> clist = stuUserDao.findSelectedSch(stuId);/
///////////查询学生所选校选课程,dao类调用点
if(request.getAttribute("list")==null){
request.setAttribute("list", list);//关键的返回值设置,使得在jsp中可以直接用${list.成员}将其取得值
request.setAttribute("number", number);
}
request.setAttribute("clist", clist);
//关键的返回值设置
return mapping.findForward("selectSch");//关键的
转到选择校选课页面,也就是取list,clist的页面
}
public List<Course> findSelectedSch
(int stuId){////////////根据学生编号查找已选的校选修课程
Query q = getSession().createQuery("FROM Course WHERE id
IN(SELECT courseId FROM StuCourse WHERE stuId=?) AND courseType
IN('校选人文','校选自然')");
q.setInteger(0, stuId);
List<Course> list = q.list()
;
System.out.println("查询出学生已选的课程");
return list;
}
五、再调用了stuUserDao类:
public Map<String,Object> findSchCourse
(){//////////////////查出学生可选的校选课
Map map =new HashMap();
String sql = "FROM Course WHERE courseType IN('校选人文','校选自然') AND remain>0 AND selective='可选'";
List<Course> list = getHibernateTemplate().find(sql);
map.put("list", list);
Iterator it = list.iterator();
int i=0;
while(it.hasNext()){
it.next();
i++;
}
map.put("number", i);
return map;
}
六、返回到.jsp
1.<html:form action="/stuUser.do?method=insertSch">
<table width="760" align="center" cellspacing="0">
<tr>
<td height="30" align="center" > </td>
<td align="center" ><strong>课程名称</strong></td>
<td align="center" ><strong>课程安排</strong></td>
<td align="center" ><strong>上课时间</strong></td>
<td align="center" ><strong>上课地点</strong></td>
<td align="center" ><strong>授课教师</strong></td>
<td align="center" ><strong>课程学分</strong></td>
<td align="center" ><strong>课程类型</strong></td>
<td align="center" ><strong>总量</strong></td>
<td align="center" ><strong>余额</strong></td>
<td align="center" ><strong>是否可选</strong></td>
</tr>
<%int i=0;%>
<logic:iterate id="list" name="list">
<%i++;request.setAttribute("nt",i); %><!-- 实现单选 -->
<tr>
<td height="30" valign="middle">
<html:checkbox property="id" value="${list.id}"
onclick="validate(${requestScope.nt})"></html:checkbox>
</td>
<td valign="middle" bgcolor="#ffffff">${list.courseName}</td>
<td valign="middle" bgcolor="#ffffff">第${list.startTime}-${list.finishTime}周</td>
<td valign="middle" bgcolor="#ffffff">${list.week}${list.time}</td>
<td valign="middle" bgcolor="#ffffff">${list.courseAddr}</td>
<td valign="middle" bgcolor="#ffffff">${list.courseTch}</td>
<td valign="middle" bgcolor="#ffffff">${list.courseCredit}</td>
<td valign="middle" bgcolor="#ffffff">${list.courseType}</td>
<td valign="middle" bgcolor="#ffffff">${list.total}</td>
<td valign="middle" bgcolor="#ffffff">${list.remain}</td>
<td valign="middle" bgcolor="#ffffff">${list.selective}</td>
</tr>
</logic:iterate>
<tr>
<td align="left"> <html:submit>提交</html:submit></td>
</tr>
</table>
</html:form>
2.<table width="780" align="center" cellspacing="0">
<tr>
<td>已选课程</td>
</tr>
<tr>
<td ><strong>课程名称</strong></td>
<td ><strong>课程安排</strong></td>
<td ><strong>上课时间</strong></td>
<td ><strong>上课地点</strong></td>
<td ><strong>授课教师</strong></td>
<td ><strong>课程学分</strong></td>
<td ><strong>课程类型</strong></td>
<td ><strong>总量</strong></td>
<td ><strong>余额</strong></td>
<td ><strong>是否可选</strong></td>
</tr>
<c:if test="${!empty clist}">
<logic:iterate id="clist" name="clist">
<tr>
<td valign="middle" bgcolor="#ffffff">${clist.courseName}</td>
<td valign="middle" bgcolor="#ffffff">第${clist.startTime}-${clist.finishTime}周</td>
<td valign="middle" bgcolor="#ffffff">${clist.week}${clist.time}</td>
<td valign="middle" bgcolor="#ffffff">${clist.courseAddr}</td>
<td valign="middle" bgcolor="#ffffff">${clist.courseTch}</td>
<td valign="middle" bgcolor="#ffffff">${clist.courseCredit}</td>
<td valign="middle" bgcolor="#ffffff">${clist.courseType}</td>
<td valign="middle" bgcolor="#ffffff">${clist.total}</td>
<td valign="middle" bgcolor="#ffffff">${clist.remain}</td>
<td valign="middle" bgcolor="#ffffff">已选</td>
<td >
<html:link page="/stuUser.do?method=dropCourse"
paramId="id" paramName="clist" paramProperty="id">退选</html:link>
</td>
</tr>
</logic:iterate>
</c:if>
<tr>
<td height="85" colspan="2" align="center" background="images/bottomU.gif"> </td>
</tr>
</table>
发表评论
-
Unity3DHouse中成功删除信息
2011-08-10 01:12 843//在jsp页面传入的参数在Action类中调用deleteH ... -
hibernate3.0中实现修改数据记录
2011-08-10 01:11 7091.查询页面中传入参数: <a href=& ... -
Unity3DHouse4项目save(object1)到库问题的解决
2011-08-10 01:10 7281.添加时点击没有任何响应和提示,google了一遍有说是 ... -
Unity3DHouse4系统未解问题
2011-08-10 01:08 8191.struts1.2+spring 2.2+Hibern ... -
Struts表单提交的text String数据可以作为HQL中的Integer类型处理
2011-08-10 01:06 9081.传入数据的表单中的声明 :<form metho ... -
6月28日房产的登录模块报错
2011-08-10 01:04 8471.JSP语法报错 exception org.ap ... -
struts的jsp Action中传入EL表达式参数及myeclipse操作技巧(涛)
2011-08-10 01:03 9131.<a href="/searchBuild ... -
Struts标签之Cannot find bean under name org.apache.struts.taglib.html.BEAN错误
2011-08-10 01:02 1322Cannot find bean under name ... -
【转】关于在HQL中的模糊查询问题
2011-08-10 01:02 799来自:20 ... -
Struts中的Action二次请求不认路径../的解决方法
2011-08-10 01:00 877地址栏没有了项目名称:http://localhost:808 ... -
myEclipse项目部署问题之解决方法
2011-08-10 00:58 1039myeclipse下工程: 1.安装myclipse时6.5 ... -
Strut2的属性驱动,模型驱动的理解
2011-08-10 00:58 1105因为在struts1的版本中,属性的拦截以及控制的处 ... -
Hibernate注释中的参照完整性和复合主键类解析
2011-08-10 00:57 1075在引入了或声明了相关表或类后就能够使用它下面的方法,例如: ... -
【转】hibernate的@EmbeddedId嵌入式主键类详解
2011-08-10 00:56 1068复合主键也可以采用 ... -
Spring 2.*有注释的配置文件中各层配置详解
2011-08-10 00:55 873<?xml version="1.0" ... -
Spring 2.5注释程序执行过程和融合xml使用
2011-08-10 00:54 866Spring2.5注释 一、加载Spirng容器,在web. ... -
【转】Struts2注解使用解析
2011-08-10 00:54 839如果希望使用 struts2 ... -
《转》struts.xml 模块化管理
2011-08-10 00:52 842... -
《转改》Struts2和Spring的集成原理
2011-08-10 00:50 7112009年09月02日 星期三 下午 ... -
房产销售系统的服务器配置问题?
2011-08-10 00:48 727Tomcat在外面的安装时抛出404找不到资源,测试后 ...
相关推荐
整合Spring和Struts2的主要目标是利用Spring的强大功能来管理Struts2中的Action类以及相关的业务逻辑,同时借助Struts2的优秀表现力来处理用户界面和请求转发。 **整合步骤:** 1. **配置环境**:确保已经安装了...
<result name="showdetails">showdetails.jsp <result name="userError">userError.jsp <result name="showCommodityClass">showCommodityClass.jsp <result name="showCar" type="redirect">showCar.jsp ...
3. 在“beans.xml”中配置SessionFactory和DAO。 至此,一个基本的SSH项目框架已经在Eclipse中搭建完成。运行项目,通过访问相应的URL,如“http://localhost:8080/SSHProject/hello.action”,应该能看到预期的...
SSH框架,全称为Struts2、Spring和Hibernate,是Java Web开发中常用的一种集成框架,它结合了MVC模式的Struts2、依赖注入的Spring以及对象关系映射的Hibernate。这个框架组合可以帮助开发者更高效地构建应用程序,...
使用帮助:http://blog.csdn.net/ptianfeng/article/details/8217176 JSF2.xdatatable分页控件与左侧菜单最简单应用 JSF2.x,功能强大,使用方便。全世界使用JSF的人越来越多。而且也有很多很好的控件给发出来...