hibernate与Struts框架结合编写简单针对修改练习
失败页面fail.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
操作失败!
</body>
</html>
页面列表jsp.
<%@page import="com.hanqi.entity.Student"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body> <% List<Student> ls=(List<Student>)request.getAttribute("Studentlist"); for(Student st:ls)
{
out.print(st+"【<a href='deleteStudent?sno="+st.getSno()
+"'>删除</a>】【<a href='updateStudent?sno="+st.getSno()+"'>修改</a>】<br>");
} %>
</body>
</html>
修改页面jsp
<%@page import="com.hanqi.entity.Student"%>
<%@page import="com.hanqi.service.StudentService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Student st=(Student)request.getAttribute("student");
%>
修改界面
<form action="update" method="post">
学号:<input type="text" name="student.sno" value=<%=st.getSno() %> readonly="readonly">
<br><br>
年龄:<input type="text" name="student.age" value=<%=st.getAge() %>>
<br><br>
姓名:<input type="text" name="student.sname" value=<%=st.getSname() %>>
<br><br>
生日:<input type="text" name="student.birthday" value=<%=st.getBirthday() %>>
<br><br>
金额:<input type="text" name="student.money" value=<%=st.getMoney() %>>
<br><br>
<input type="submit" value="提交"> </form> </body>
</html>
Dao包
//查询单条信息
public Student query(int sno)
{
init();
Student st=(Student)se.get(Student.class, sno);
destroy();
return st;
} //修改方法
public void update(Student student)
{
init();
se.saveOrUpdate(student);
destroy(); }
service包
//查询单条信息
public Student query(int sno)
{
return new StudentDao().query(sno);
} //修改
public void update(Student student)
{
new StudentDao().update(student);
}
Action类
package com.hanqi.action; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.interceptor.ServletRequestAware; import com.hanqi.entity.Student;
import com.hanqi.service.StudentService; public class StudentAction implements ServletRequestAware { private HttpServletRequest hsr; //欲模型方式
private Student student; public Student getStudent() {
return student;
} public void setStudent(Student student) {
this.student = student;
} //查询单挑信息
public String update()
{
String rtn="fail";
try{
String sno=hsr.getParameter("sno");
Student st=new StudentService().query(Integer.parseInt(sno));
hsr.setAttribute("student", st);
rtn="ok"; }catch(Exception e)
{
e.printStackTrace();
}
return rtn;
} //修改
public String updateStudent()
{
String rtn="fail";
try{
new StudentService().update(student); rtn="ok";
}catch(Exception e)
{
e.printStackTrace();
}
return rtn;
} @Override
public void setServletRequest(HttpServletRequest arg0) { hsr=arg0;
}
Struts.xml文件
<!-- 查询单条信息 -->
<action name="updateStudent" class="com.hanqi.action.StudentAction" method="update">
<result name="ok">/WEB-INF/pages/update.jsp</result>
<result name="fail">/WEB-INF/pages/fail.jsp</result>
</action> <!-- 修改 -->
<action name="update" class="com.hanqi.action.StudentAction" method="updateStudent">
<result name="ok" type="redirectAction">selectStudent</result>
<result name="fail">/WEB-INF/pages/fail.jsp</result>
</action>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Test21</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> <filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
hibernate.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory >
<!-- 连接数据库 -->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="hibernate.connection.username">test01</property>
<!-- 数据库方案 -->
<property name="hibernate.default_schema">TEST01</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- 调试 -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!-- 自动建表方式 -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 注册映射文件 -->
<mapping resource="com/hanqi/entity/Student.hbm.xml"/> </session-factory>
</hibernate-configuration>
hibernate与Struts框架结合编写简单针对修改练习的更多相关文章
- hibernate与struts框架实现增删改查
这里配置hibernate与struts不再过多赘述,配置搭建前文已经详细讲解,配置如下: hibernate.hbm.xml配置: <?xml version="1.0" ...
- 利用hibernate与struts框架制作简单注册界面
一:配置hibernate 1.导包 hibernate包和jdbc连接mysql数据库的包 2.实用工具生成hibernate配置文件和映射文件 3.做好hibernateUtil生成session ...
- java中从Spring、Hibernate和Struts框架的action、service和dao三层结构异常处理体系设计
Spring的事务实现采用基于AOP的拦截器来实现,如果没有在事务配置的时候注明回滚的checked exception,那么只有在发生了unchecked exception的时候,才会进行事务回滚 ...
- 详谈Struts+Hibernate+Spring三大框架
前言:对于JAVA WEB端的程序员来说,对JAVA三大框架:Struts+Hibernate+Spring的了解必不可缺,下面详细谈谈 Java三大框架主要用来做WEN应用. 三大框架:Struts ...
- Java - Struts框架教程 Hibernate框架教程 Spring框架入门教程(新版) sping mvc spring boot spring cloud Mybatis
https://www.zhihu.com/question/21142149 http://how2j.cn/k/hibernate/hibernate-tutorial/31.html?tid=6 ...
- Struts1、Struts2、Hibernate、Spring框架工作原理介绍
Struts1工作原理 Struts1工作原理图 1.初始化:struts框架的总控制器ActionServlet是一个Servlet,它在web.xml中配置成自动启动的Servlet,在启动时总控 ...
- javaWeb项目(SSH框架+AJAX+百度地图API+Oracle数据库+MyEclipse+Tomcat)之一 基础Struts框架搭建篇
即将开始着手写这个项目,所以希望通过这篇博客来记录自己学习的过程 今天开学第一天,就上了软件工程实践课,自己也开始着手做这个大作业了.首先我的项目名称叫做智能班车管理系统. 项目的概况: 该软件产品是 ...
- Struts框架详解
1.Struts应用框架介绍 (1)框架 框架最简单的形式是指已开发过并已测试过的软件的程序块,这些程序块可以在多个软件开发工程中重用.框架提供了一个概括的体系结构模版,可以用这个模板来构建特定领域中 ...
- Struts框架的核心业务
Struts的核心业务 Struts核心业务有很多,这里主要介绍了比较简单一些的: 请求数据的处理,和数据自动封装,类型自动转换 1.Struts中数据处理 1.1.方式1:直接过去servletap ...
随机推荐
- 如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成
阅读目录 前言 建模 实现 结语 一.前言 前面几篇已经实现了一个基本的购买+售价计算的过程,这次再让售价丰满一些,增加一个会员价的概念.会员价在现在的主流电商中,是一个不大常见的模式,其带来的问题是 ...
- C# 利用性能计数器监控网络状态
本例是利用C#中的性能计数器(PerformanceCounter)监控网络的状态.并能够直观的展现出来 涉及到的知识点: PerformanceCounter,表示 Windows NT 性能计数器 ...
- 微信小程序体验(2):驴妈妈景区门票即买即游
驴妈妈因为出色的运营能力,被腾讯选为首批小程序内测单位.驴妈妈的技术开发团队在很短的时间内完成了开发任务,并积极参与到张小龙团队的内测问题反馈.驴妈妈认为,移动互联网时代,微信是巨大的流量入口,也是旅 ...
- HTML5 progress和meter控件
在HTML5中,新增了progress和meter控件.progress控件为进度条控件,可表示任务的进度,如Windows系统中软件的安装.文件的复制等场景的进度.meter控件为计量条控件,表示某 ...
- .NET Core的日志[4]:将日志写入EventLog
面向Windows的编程人员应该不会对Event Log感到陌生,以至于很多人提到日志,首先想到的就是EventLog.EventLog不仅仅记录了Windows系统自身针对各种事件的日志,我们的应用 ...
- 【原创分享·微信支付】C# MVC 微信支付教程系列之现金红包
微信支付教程系列之现金红包 最近最弄这个微信支付的功能,然后扫码.公众号支付,这些都做了,闲着无聊,就看了看微信支付的其他功能,发现还有一个叫“现金红包”的玩意,想 ...
- AFNetworking 3.0 源码解读(六)之 AFHTTPSessionManager
AFHTTPSessionManager相对来说比较好理解,代码也比较短.但却是我们平时可能使用最多的类. AFNetworking 3.0 源码解读(一)之 AFNetworkReachabilit ...
- Nexus(一)环境搭建
昨天,成功搭建了自己的 Maven 环境(详见:Maven(一)环境搭建),今天就来研究和探讨下 Nexus 的搭建! 使用背景: 安装环境:Windows 10 -64位 JDK版本:1.7 Mav ...
- [异常特工]android常见bug跟踪
前言 对app的线上bug的收集(友盟.云捕等)有时会得到这样的异常堆栈信息:没有一行代码是有关自身程序代码的.这使得对bug的解决无从下手,根据经验,内存不足OOM,Dialog关闭,ListVie ...
- mono for android Listview 里面按钮 view Button click 注册方法 并且传值给其他Activity 主要是context
需求:为Listview的Item里面的按钮Button添加一个事件,单击按钮时通过事件传值并跳转到新的页面. 环境:mono 效果: 布局代码 主布局 <?xml version=" ...