总结的几点:

  1、在jsp中注意<%! %>声明代码块中的变量只会在项目开始的时候第一次运行jsp的时候执行一遍,有点类似于java类中的static代码块,所以如果是会改变的值不应该声明在这里面。而是卸载<%%>代码块中

  2、使用js中的location.href有时候就是无法生效,也就是无法跳转到你想要的页面。你可以在location.href语句后面加上 event.returnValue=false即可

  3、进行编辑一条信息或者删除信息的时候id字段可以使用隐藏域或者直接使用el传递。这样就不需要通过js找到id列或者其他了

  4、在增加的时候注意在servlet或者对应的jsp进行对象的补全

  5、在修改的时候如果有那种类似于下拉列表或者单选按钮的东西,可以使用jstl中的<c:if>实现选择。

例子:

  1. CREATE TABLE profile(
  2. id NUMBER PRIMARY KEY,
  3. name VARCHAR2(20),
  4. birthday DATE,
  5. gender VARCHAR2(10),
  6. career VARCHAR2(20),
  7. address VARCHAR2(50),
  8. mobile VARCHAR2(11)
  9. );
  10.  
  11. CREATE SEQUENCE seq_profile;
  12.  
  13. package com.dao;
  14.  
  15. import java.sql.Connection;
  16. import java.sql.SQLException;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19.  
  20. import org.apache.commons.dbutils.QueryRunner;
  21. import org.apache.commons.dbutils.ResultSetHandler;
  22. import org.apache.commons.dbutils.handlers.BeanHandler;
  23. import org.apache.commons.dbutils.handlers.BeanListHandler;
  24.  
  25. import com.domain.Profile;
  26. import com.jdbc.JdbcUtils;
  27.  
  28. public class ProfileDao {
  29. /**
  30. * zeng
  31. * @param p
  32. * @throws SQLException
  33. */
  34. public void addProfile(Profile p) throws SQLException{
  35. String sql="INSERT INTO profile VALUES (seq_profile.NEXTVAL,?,?,?,?,?,?)";
  36. QueryRunner qr=new QueryRunner();
  37. Connection con=JdbcUtils.getConnection();
  38. Object[] params={p.getName(),p.getBirthday(),p.getGender(),p.getCareer(),p.getAddress(),p.getMobile()};
  39. qr.update(con, sql,params);
  40. JdbcUtils.releaseConnection(con);
  41. }
  42.  
  43. public void deleteById(int id) throws SQLException{
  44. String sql="DELETE FROM profile WHERE id=?";
  45. QueryRunner qr=new QueryRunner();
  46. Connection con=JdbcUtils.getConnection();
  47. Object[] params={id};
  48. qr.update(con,sql, params);
  49. JdbcUtils.releaseConnection(con);
  50. }
  51.  
  52. public void update(Profile p) throws SQLException{
  53. String sql="UPDATE profile SET name=?,birthday=?,gender=?,career=?,address=?,mobile=? WHERE id=?";
  54. QueryRunner qr=new QueryRunner();
  55. Connection con=JdbcUtils.getConnection();
  56. Object[] params={p.getName(),p.getBirthday(),p.getGender(),p.getCareer(),p.getAddress(),p.getMobile(),p.getId()};
  57. // System.out.println(Arrays.toString(params));
  58. qr.update(con,sql, params);
  59. JdbcUtils.releaseConnection(con);
  60. }
  61.  
  62. public ArrayList<Profile> findAll() throws SQLException{
  63. String sql="SELECT * FROM profile";
  64. QueryRunner qr=new QueryRunner();
  65. Connection con=JdbcUtils.getConnection();
  66. ResultSetHandler<List<Profile>> rsh=new BeanListHandler<Profile>(Profile.class);
  67. ArrayList<Profile> profiles=(ArrayList<Profile>) qr.query(con, sql, rsh);
  68. JdbcUtils.releaseConnection(con);
  69. return profiles;
  70. }
  71.  
  72. public Profile load(int id) throws SQLException{
  73. String sql="SELECT * FROM profile WHERE id=?";
  74. QueryRunner qr=new QueryRunner();
  75. Object[] params={id};
  76. Connection con=JdbcUtils.getConnection();
  77. ResultSetHandler<Profile> rsh=new BeanHandler<Profile>(Profile.class);
  78. Profile profile= (Profile) qr.query(con, sql, rsh,params);
  79. JdbcUtils.releaseConnection(con);
  80. return profile;
  81. }
  82.  
  83. }
  84.  
  85. package com.domain;
  86.  
  87. import java.io.Serializable;
  88. import java.sql.Date;
  89.  
  90. public class Profile implements Serializable{
  91.  
  92. private static final long serialVersionUID = 1L;
  93. private int id;
  94. private String name;
  95. private Date birthday;
  96. private String gender;
  97. private String career;
  98. private String address;
  99. private String mobile;
  100. @Override
  101. public String toString() {
  102. return "Profile [id=" + id + ", name=" + name + ", birthday="
  103. + birthday + ", gender=" + gender + ", career=" + career
  104. + ", address=" + address + ", mobile=" + mobile + "]";
  105. }
  106. public int getId() {
  107. return id;
  108. }
  109. public void setId(int id) {
  110. this.id = id;
  111. }
  112. public String getName() {
  113. return name;
  114. }
  115. public void setName(String name) {
  116. this.name = name;
  117. }
  118. public Date getBirthday() {
  119. return birthday;
  120. }
  121. public void setBirthday(Date birthday) {
  122. this.birthday = birthday;
  123. }
  124. public String getGender() {
  125. return gender;
  126. }
  127. public void setGender(String gender) {
  128. this.gender = gender;
  129. }
  130. public String getCareer() {
  131. return career;
  132. }
  133. public void setCareer(String career) {
  134. this.career = career;
  135. }
  136. public String getAddress() {
  137. return address;
  138. }
  139. public void setAddress(String address) {
  140. this.address = address;
  141. }
  142. public String getMobile() {
  143. return mobile;
  144. }
  145. public void setMobile(String mobile) {
  146. this.mobile = mobile;
  147. }
  148. public Profile() {
  149. super();
  150. // TODO Auto-generated constructor stub
  151. }
  152. public Profile(int id, String name, Date birthday, String gender,
  153. String career, String address, String mobile) {
  154. super();
  155. this.id = id;
  156. this.name = name;
  157. this.birthday = birthday;
  158. this.gender = gender;
  159. this.career = career;
  160. this.address = address;
  161. this.mobile = mobile;
  162. }
  163.  
  164. }
  165.  
  166. package com.jdbc;
  167.  
  168. import java.sql.Connection;
  169. import java.sql.SQLException;
  170.  
  171. import javax.sql.DataSource;
  172.  
  173. import com.mchange.v2.c3p0.ComboPooledDataSource;
  174.  
  175. public class JdbcUtils {
  176. /*
  177. * 配置文件的恶魔人配置!要求你必须给出c3p0-config。xnl!
  178. */
  179. private static ComboPooledDataSource dataSource=new ComboPooledDataSource("oracle-config");
  180. /**
  181. * 它是事务专用连接
  182. */
  183. private static Connection con=null;
  184. /**
  185. * 使用连接池返回一个连接对象
  186. * @return
  187. * @throws SQLException
  188. */
  189. public static Connection getConnection() throws SQLException{
  190. //当con!=null,表示已经调用过beginTransaction方法了
  191. if(con!=null) return con;
  192. return dataSource.getConnection();
  193. }
  194.  
  195. /**
  196. * 返回连接池对象
  197. * @return
  198. */
  199. public static DataSource getDataSource(){
  200. return dataSource;
  201. }
  202. /**
  203. * 1、开启一个Connection,设置它的setAutoCommit(false)
  204. * 2、还要保证dao中使用的连接是我们刚刚创建的
  205. * ------------------------
  206. * 1、创建一个Connection,设置为手动提交
  207. * 2、把这个Connection给dao用
  208. * 3、还要让commitTransaction或rollbackTransaction可以获取到
  209. * @throws SQLException
  210. */
  211. public static void beignTransaction() throws SQLException{
  212. if(con!=null) throw new SQLException("已经开始了事务,就不要继续开启事务了!");
  213. con=getConnection();
  214. con.setAutoCommit(false);
  215. }
  216. /**
  217. * 提交事务
  218. * 获取之前开启的Connection,兵提交
  219. * @throws SQLException
  220. */
  221. public static void commitTransaction() throws SQLException{
  222. if(con==null) throw new SQLException("还没有开启事务,不能提交!");
  223. con.commit();
  224. con.close();
  225. con=null;//因为前面的close()不会销毁连接而是放回连接池
  226. }
  227. /**
  228. * 回滚事务
  229. * 获取之前开启的Connection,兵回滚
  230. * @throws SQLException
  231. */
  232. public static void rollbackTransaction() throws SQLException{
  233. if(con==null) throw new SQLException("还没有开启事务,不能提交!");
  234. con.rollback();
  235. con.close();
  236. con=null;//因为前面的close()不会销毁连接而是放回连接池
  237. }
  238.  
  239. public static void releaseConnection(Connection connection) throws SQLException{
  240. /*
  241. *判斷它是不是中事務專用,如果是就不關閉
  242. *如果不是就要關閉
  243. */
  244. //如果con==null,說明沒有事務,那麼connection一定不是事務專用的
  245. if(con==null) connection.close();
  246. if(con!=connection) connection.close();
  247.  
  248. }
  249. }
  250.  
  251. package com.service;
  252.  
  253. import java.sql.SQLException;
  254. import java.util.ArrayList;
  255.  
  256. import com.dao.ProfileDao;
  257. import com.domain.Profile;
  258.  
  259. public class ProfileService {
  260.  
  261. private ProfileDao profileDao=new ProfileDao();
  262.  
  263. public void addProfile(Profile p){
  264. try {
  265. profileDao.addProfile(p);
  266. } catch (SQLException e) {
  267. e.printStackTrace();
  268. }
  269. }
  270.  
  271. public void deleteProfile(int id){
  272. try {
  273. profileDao.deleteById(id);
  274. } catch (SQLException e) {
  275. e.printStackTrace();
  276. }
  277. }
  278.  
  279. public void updateProfile(Profile p){
  280. try {
  281. profileDao.update(p);
  282. } catch (SQLException e) {
  283. e.printStackTrace();
  284. }
  285. }
  286.  
  287. public ArrayList<Profile> findAll(){
  288. try {
  289. return profileDao.findAll();
  290. } catch (SQLException e) {
  291. throw new RuntimeException(e);
  292. }
  293. }
  294.  
  295. public Profile findById(int id){
  296. try {
  297. return profileDao.load(id);
  298. } catch (SQLException e) {
  299. throw new RuntimeException(e);
  300. }
  301. }
  302. }
  303.  
  304. package com.test;
  305.  
  306. import java.sql.Date;
  307. import java.text.ParseException;
  308. import java.text.SimpleDateFormat;
  309.  
  310. import org.junit.Test;
  311.  
  312. import com.domain.Profile;
  313. import com.service.ProfileService;
  314.  
  315. public class Test01 {
  316.  
  317. @Test
  318. public void fun1() throws ParseException{
  319. ProfileService ps=new ProfileService();
  320. Profile p=new Profile();
  321. p.setName("liu");
  322.  
  323. p.setBirthday(geDate("1994-10-12"));
  324. p.setAddress("江西");
  325. p.setGender("女");
  326. p.setMobile("8482973");
  327. p.setCareer("学生");
  328. ps.addProfile(p);
  329. // p.setCareer("工人");
  330. // p.setId(1);
  331. // ps.updateProfile(p);
  332. // System.out.println(ps.findAll());
  333. // System.out.println(ps.findById(1));
  334. }
  335.  
  336. public Date geDate(String date) throws ParseException{
  337. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  338. return new Date(sdf.parse(date).getTime());
  339. }
  340. }
  341.  
  342. <?xml version="1.0" encoding="UTF-8" ?>
  343. <c3p0-config>
  344. <!-- 默认连接配置 -->
  345. <default-config>
  346. <!-- 连接四大参数配置 -->
  347. <property name="jdbcUrl">jdbc:mysql://127.0.0.1:3306/demo</property>
  348. <property name="driverClass">com.mysql.jdbc.Driver</property>
  349. <property name="user">guodaxia</property>
  350. <property name="password">961012gz</property>
  351. <!-- 池参数配置 -->
  352. <property name="acquireIncrement">3</property>
  353. <property name="initialPoolSize">10</property>
  354. <property name="minPoolSize">2</property>
  355. <property name="maxPoolSize">10</property>
  356. </default-config>
  357.  
  358. <named-config name="oracle-config">
  359. <!-- 连接四大参数配置 -->
  360. <property name="jdbcUrl">jdbc:oracle:thin:@localhost:1521:db</property>
  361. <property name="driverClass">oracle.jdbc.driver.OracleDriver</property>
  362. <property name="user">scott</property>
  363. <property name="password">961012gz</property>
  364. <property name="acquireIncrement">3</property>
  365. <property name="initialPoolSize">10</property>
  366. <property name="minPoolSize">2</property>
  367. <property name="maxPoolSize">10</property>
  368. </named-config>
  369.  
  370. </c3p0-config>
  371.  
  372. $(function(){
  373.  
  374. $("button[name='show']").click(function(){
  375. var id=$($(this).parents("tr").find("td")[0]).text();
  376. //alert(id);
  377. window.location.href="detail.jsp?id="+id;
  378. });
  379.  
  380. $("button[name='alert']").click(function(){
  381. var id=$($(this).parents("tr").find("td")[0]).text();
  382. //alert(id);
  383. window.location.href="update.jsp?id="+id;
  384. });
  385.  
  386. $("button[name='delete']").click(function(){
  387. var id=$($(this).parents("tr").find("td")[0]).text();
  388. //alert(id);
  389. window.location.href="delete.jsp?id="+id;
  390. });
  391.  
  392. });
  393.  
  394. $(function(){
  395.  
  396. $("option").each(function(){
  397. var v1=$("#hhh").val();
  398. var v2=$(this).val();
  399. //alert($("#hhh").val()+" "+$(this).val());
  400. if(v1==v2){
  401. $(this).attr("selected",true);
  402. }
  403. });
  404.  
  405. $("button[name='back'").click(function(){
  406. //alert(1);
  407. window.location.href="list.jsp?date="+new Date().getTime();
  408. event.returnValue=false;
  409. });
  410.  
  411. });
  412.  
  413. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  414. <%
  415. String path = request.getContextPath();
  416. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  417. %>
  418.  
  419. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  420. <html>
  421. <head>
  422. <base href="<%=basePath%>">
  423.  
  424. <title>My JSP 'index.jsp' starting page</title>
  425. <meta http-equiv="pragma" content="no-cache">
  426. <meta http-equiv="cache-control" content="no-cache">
  427. <meta http-equiv="expires" content="0">
  428. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  429. <meta http-equiv="description" content="This is my page">
  430. <!--
  431. <link rel="stylesheet" type="text/css" href="styles.css">
  432. -->
  433. </head>
  434.  
  435. <body>
  436. <%
  437. response.sendRedirect(path+"/list.jsp");
  438. %>
  439. </body>
  440. </html>
  441.  
  442. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  443. <%@ page import="com.domain.Profile,java.sql.Date,com.service.ProfileService,java.text.SimpleDateFormat" %>
  444.  
  445. <%
  446. String path = request.getContextPath();
  447. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  448. %>
  449.  
  450. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  451. <html>
  452. <head>
  453. <base href="<%=basePath%>">
  454.  
  455. <title>My JSP 'list.jsp' starting page</title>
  456.  
  457. <meta http-equiv="pragma" content="no-cache">
  458. <meta http-equiv="cache-control" content="no-cache">
  459. <meta http-equiv="expires" content="0">
  460. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  461. <meta http-equiv="description" content="This is my page">
  462. <!--
  463. <link rel="stylesheet" type="text/css" href="styles.css">
  464. -->
  465. <style type="text/css">
  466. td{
  467. /* width:80px; */
  468. border:1px solid;
  469. }
  470. table{
  471. border:1px solid;
  472. }
  473. #tr1{
  474. background-color: yellow;
  475. }
  476. </style>
  477. <script type="text/javascript" src="js/jquery1.8.3.js"></script>
  478. <script type="text/javascript" src="js/list.js"></script>
  479. </head>
  480. <%
  481. ProfileService ps=new ProfileService();
  482. ArrayList<Profile> profiles=ps.findAll();
  483. %>
  484. <%!
  485.  
  486. String date2Str(Date d){
  487. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  488. return sdf.format(d);
  489. }
  490. %>
  491. <body>
  492. <table>
  493. <tr id="tr1">
  494. <td>编号</td>
  495. <td>姓名</td>
  496. <td>生日</td>
  497. <td>性别</td>
  498. <td>职业</td>
  499. <td>住所</td>
  500. <td>电话</td>
  501. <td>操作</td>
  502. </tr>
  503. <%for(Profile p:profiles){%>
  504. <tr>
  505. <td><%=p.getId() %></td>
  506. <td><%=p.getName() %></td>
  507. <td><%=date2Str(p.getBirthday()) %></td>
  508. <td><%=p.getGender() %></td>
  509. <td><%=p.getCareer() %></td>
  510. <td><%=p.getAddress() %></td>
  511. <td><%=p.getMobile() %></td>
  512. <td>
  513. <button name="show" >明细</button>
  514. <button name="alert" >修改</button>
  515. <button name="delete" >删除</button>
  516. </td>
  517. </tr>
  518. <%
  519. }
  520. %>
  521.  
  522. </table>
  523. </body>
  524. </html>
  525.  
  526. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  527. <%@ page import="com.domain.Profile,java.sql.Date,com.service.ProfileService,java.text.SimpleDateFormat" %>
  528. <%
  529. String path = request.getContextPath();
  530. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  531. %>
  532.  
  533. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  534. <html>
  535. <head>
  536. <base href="<%=basePath%>">
  537.  
  538. <title>My JSP 'update.jsp' starting page</title>
  539.  
  540. <meta http-equiv="pragma" content="no-cache">
  541. <meta http-equiv="cache-control" content="no-cache">
  542. <meta http-equiv="expires" content="0">
  543. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  544. <meta http-equiv="description" content="This is my page">
  545. <!--
  546. <link rel="stylesheet" type="text/css" href="styles.css">
  547. -->
  548.  
  549. <style type="text/css">
  550. table{
  551. border:1px solid;
  552. }
  553. td{
  554. border:1px solid;
  555. }
  556. </style>
  557. <script type="text/javascript" src="js/jquery1.8.3.js"></script>
  558. <script type="text/javascript" src="js/update.js"></script>
  559. </head>
  560.  
  561. <body>
  562. <%!
  563. Profile p=null;
  564. String date2Str(Date d){
  565. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  566. return sdf.format(d);
  567. }
  568. %>
  569. <%
  570. Integer i=Integer.valueOf(request.getParameter("id"));
  571. ProfileService ps=new ProfileService();
  572. p=ps.findById(i);
  573. %>
  574. <form action="utu.jsp" method="post">
  575. <table>
  576. <tr>
  577. <td>编号</td>
  578. <td><input name="id" type="text" value="<%=p.getId() %>" readonly></td>
  579. </tr>
  580. <tr>
  581. <td>姓名</td>
  582. <td><input name="name" type="text" value="<%=p.getName() %>" ></td>
  583. </tr>
  584. <tr>
  585. <td>生日</td>
  586. <td><input name="birthday" type="text" value="<%=p.getBirthday() %>" ></td>
  587. </tr>
  588. <tr>
  589. <td>性别</td>
  590. <td>
  591. <select name="gender">
  592. <option value="女">女</option>
  593. <option value="男">男</option>
  594. </select>
  595. <input id="hhh" type="hidden" value="<%=p.getGender() %>">
  596. </td>
  597. </tr>
  598. <tr>
  599. <td>职业</td>
  600. <td><input name="career" type="text" value="<%=p.getCareer() %>" ></td>
  601. </tr>
  602. <tr>
  603. <td>住所</td>
  604. <td><input name="address" type="text" value="<%=p.getAddress() %>" ></td>
  605. </tr>
  606. <tr>
  607. <td>电话</td>
  608. <td><input name="mobile" type="text" value="<%=p.getMobile() %>" ></td>
  609. </tr>
  610. </table>
  611. <input type="submit" value="修改">
  612. <button name="back">返回</button>
  613. </form>
  614. </body>
  615. </html>
  616.  
  617. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  618. <%@ page import="com.domain.Profile,java.sql.Date,com.service.ProfileService,java.text.SimpleDateFormat,java.text.ParseException" %>
  619. <%
  620. String path = request.getContextPath();
  621. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  622. %>
  623. <%!
  624. Date str2Date(String str)throws ParseException{
  625. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  626. return new Date(sdf.parse(str).getTime());
  627. }
  628. %>
  629.  
  630. <%
  631. request.setCharacterEncoding("utf-8");
  632. response.setCharacterEncoding("utf-8");
  633.  
  634. int id=Integer.parseInt(request.getParameter("id"));
  635. String name=request.getParameter("name");
  636. Date birthday=str2Date(request.getParameter("birthday"));
  637. String gender=request.getParameter("gender");
  638. String career=request.getParameter("career");
  639. String address=request.getParameter("address");
  640. String mobile=request.getParameter("mobile");
  641.  
  642. System.out.println(id+"---"+name+"--"+birthday+"--"+gender+"--"+career+"--"+address+"--"+mobile);
  643. Profile p=new Profile();
  644. p.setId(id);
  645. p.setName(name);
  646. p.setBirthday(birthday);
  647. p.setGender(gender);
  648. p.setCareer(career);
  649. p.setAddress(address);
  650. p.setMobile(mobile);
  651.  
  652. ProfileService ps=new ProfileService();
  653. ps.updateProfile(p);
  654.  
  655. response.sendRedirect(path+"/update.jsp?id="+id);
  656.  
  657. %>
  658.  
  659. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  660. <%@ page import="com.domain.Profile,java.sql.Date,com.service.ProfileService,java.text.SimpleDateFormat" %>
  661. <%
  662. String path = request.getContextPath();
  663. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  664. %>
  665.  
  666. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  667. <html>
  668. <head>
  669. <base href="<%=basePath%>">
  670.  
  671. <title>My JSP 'detail.jsp' starting page</title>
  672.  
  673. <meta http-equiv="pragma" content="no-cache">
  674. <meta http-equiv="cache-control" content="no-cache">
  675. <meta http-equiv="expires" content="0">
  676. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  677. <meta http-equiv="description" content="This is my page">
  678. <!--
  679. <link rel="stylesheet" type="text/css" href="styles.css">
  680. -->
  681. <style type="text/css">
  682. table{
  683. border:1px solid;
  684. }
  685. td{
  686. border:1px solid;
  687. }
  688. </style>
  689. </head>
  690. <%!
  691. Profile p=null;
  692. String date2Str(Date d){
  693. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  694. return sdf.format(d);
  695. }
  696. %>
  697. <%
  698. Integer i=Integer.valueOf(request.getParameter("id"));
  699. ProfileService ps=new ProfileService();
  700. p=ps.findById(i);
  701. %>
  702.  
  703. <body>
  704. <table>
  705. <tr>
  706. <td>编号</td>
  707. <td><%=p.getId() %></td>
  708. </tr>
  709. <tr>
  710. <td>姓名</td>
  711. <td><%=p.getName() %></td>
  712. </tr>
  713. <tr>
  714. <td>生日</td>
  715. <td><%=p.getBirthday() %></td>
  716. </tr>
  717. <tr>
  718. <td>性别</td>
  719. <td><%=p.getGender() %></td>
  720. </tr>
  721. <tr>
  722. <td>职业</td>
  723. <td><%=p.getCareer() %></td>
  724. </tr>
  725. <tr>
  726. <td>住所</td>
  727. <td><%=p.getAddress() %></td>
  728. </tr>
  729. <tr>
  730. <td>电话</td>
  731. <td><%=p.getMobile() %></td>
  732. </tr>
  733. </table>
  734. <button onclick="javascript:history.go(-1)">返回</button>
  735. </body>
  736. </html>
  737.  
  738. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  739. <%@ page import="com.domain.Profile,java.sql.Date,com.service.ProfileService,java.text.SimpleDateFormat" %>
  740. <%
  741. int id=Integer.parseInt(request.getParameter("id"));
  742. ProfileService ps=new ProfileService();
  743. ps.deleteProfile(id);
  744. response.sendRedirect(request.getContextPath()+"/list.jsp?date="+System.currentTimeMillis());
  745. %>

jar:

  

JSP的一个增删改查例子和总结的更多相关文章

  1. 最简单的jsp+servlet的增删改查代码

    package ceet.ac.cn.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.s ...

  2. 初次尝试PHP——一个简单的对数据库操作的增删改查例子

    第一次学习PHP,很多人说PHP是最好的语言,学习了一点点,还不敢说这样的话,不过确实蛮好用的. 做了一个简单的对数据库的增删改查的操作,主要是将四种操作写成了独立的函数,之后直接调用函数.以下是代码 ...

  3. spring boot2+jpa+thymeleaf增删改查例子

    参考这遍文章做了一个例子,稍微不同之处,原文是spring boot.mysql,这里改成了spring boot 2.Oracle. 一.pom.xml引入相关模块web.jpa.thymeleaf ...

  4. 用liferay实现的增删改查例子-book管理系统

    liferay 这个框架是一个开源的项目,大家可以修改源代码,来实现自己的需求.但是关于liferay的开发资料中文的很少关于liferay的基础知识,大家可以百度学习一下,再来看下边的例子 首先需要 ...

  5. DBUtils 增删改查例子

    sql CREATE TABLE [dbo].[Person] ( , ) NOT NULL , ) COLLATE Chinese_PRC_CI_AS NULL , [age] [int] NULL ...

  6. jsp+servlet+mysql增删改查

    用的IntelliJ IDEA开发的,jdk1.8 1 首先是项目结构,如下图所示 2看各层的代码 首先是web.xml <?xml version="1.0" encodi ...

  7. MVC增删改查例子

    一.显示用户列表1.新建UserInfoController控制器 public ActionResult Index() { DataTable table = SQLHelper.ExecuteR ...

  8. JS组件系列——又一款MVVM组件:Vue(一:30分钟搞定前端增删改查)

    前言:关于Vue框架,好几个月之前就听说过,了解一项新技术之后,总是处于观望状态,一直在犹豫要不要系统学习下.正好最近有点空,就去官网了解了下,看上去还不错的一个组件,就抽空研究了下.最近园子里vue ...

  9. Redis:五种数据类型的简单增删改查

    Redis简单增删改查例子 例一:字符串的增删改查 #增加一个key为ay_key的值 127.0.0.1:6379> set ay_key "ay" OK #查询ay_ke ...

随机推荐

  1. Pexpect--example--hive.py解读

    python version 2.6.6 ; pexpect 2.3 login方法解读: def login (args, cli_username=None, cli_password=None) ...

  2. 百度地图SnapshotReadyCallback截屏

    今天碰到了地图截图的功能,不太会,查查资料知道怎么弄了,跟大家分享一下 直接上代码,弄了一个方法,将截取的图片上传至服务器,返回给我们图片路径 //获取地图截图 private void getscr ...

  3. poj2485

    Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27912   Accepted: 12734 Descri ...

  4. MFC添加菜单资源与菜单执行函数的两种命令形式

    添加资源->新建一个菜单资源->选择相应的对话框 菜单的执行函数命令形式: COMMAD 是指点击菜单后的执行命令 UPDATE_COMMAND_UI 是指点击菜单后菜单状态的函数

  5. java拾遗2----XML解析(二) SAX解析

    XML解析之SAX解析: SAX解析器:SAXParser类同DOM一样也在javax.xml.parsers包下,此类的实例可以从 SAXParserFactory.newSAXParser() 方 ...

  6. 牛人blog汇总

    1.天一思维: https://blog.csdn.net/tszty1997?t=1

  7. spring 注解管理

    一.注解准备 1.xml引入新的约束,并开启注解扫描 context:component-scan标签开启注解扫描 2.导入注解有关jar包 二.注解创建对象 1.User类 @Component( ...

  8. anaconda + opencv3

    直接运行 pip install opencv-python 或者 pip install opencv-contrib-python 参照如下网页 https://blog.csdn.net/sin ...

  9. linux 9 -- 交互式使用Bash Shell

    二十二. 交互式使用Bash Shell:     1.  用set命令设置bash的选项:     下面为set主要选项的列表及其表述: 选项名 开关缩写 描述 allexport -a 打开此开关 ...

  10. 通过systemd配置Docker

    1. systemd Service相关目录 通常情况下,我们有3种方式可以配置etcd中的service.以docker为例,1)在目录/etc/systemd/system/docker.serv ...