首页 servlet增删改查

servlet增删改查

举报
开通vip

servlet增删改查Servlet(增删改查) 准备:1.新建一个web项目(StudentZSGC) 2.分层,分包 一.查(查询学员信息表) (1)新建一个JSP页面(通过form表单进一个servlet(StudentAction)) 查询学员表 (2)通过web.xml(中转站)找到对应的servlet(StudentAction) (3)进入action层 package com.student.action; import java.io.IOException; import ja...

servlet增删改查
Servlet(增删改查) 准备:1.新建一个web项目(StudentZSGC) 2.分层,分包 一.查(查询学员信息 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf ) (1)新建一个JSP页面(通过form表单进一个servlet(StudentAction)) <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServername()+":"+request.getServerPort()+path+"/"; %> 查询学员表
(2)通过web.xml(中转站)找到对应的servlet(StudentAction) (3)进入action层 package com.student.action; import java.io.IOException; import java.util.List; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.student.service.StudentService; public class StudentAction extends HttpServlet { /** * 查询所有人员 */ private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //转码 req.setCharacterEncoding("utf-8"); resp.setCharacterEncoding("utf-8"); resp.setContentType("text/html; charset=utf-8"); //调方法 StudentService studentService=new StudentService(); List> list=null; list=studentService.selectAll(); req.setAttribute("StudentList", list);--传回前台进行set //转向 if(!list.isEmpty()){        --跳转到该页面 req.getRequestDispatcher("Student.jsp").forward(req, resp); }else{ req.getRequestDispatcher("Student.jsp").forward(req, resp); } } } (4)进入service类中 package com.student.service; import java.util.List; import java.util.Map; import com.student.dao.StudentDao; /** * 查询所有学员信息方法 * @author Administrator */ public class StudentService { public List> selectAll() { StudentDao  StudentDao=new StudentDao(); return StudentDao.selectAll(); } } (5)进入dao中连接数据库 package com.student.dao; import java.util.List; /** * 查询数据库所有学员 放到list中 */ import java.util.Map; import com.student.util.Dao; public class StudentDao { Dao dao=new Dao(); public List> selectAll() { String sql="select s_id, s_number, s_name, s_sex, s_class, s_age, s_add, s_college, s_mobile, s_hobby from student"; return dao.select(sql,new Object[]{}); } } (6)查询出数据后跳到Student.jsp页面 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@page import="java.sql.Array"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServername()+":"+request.getServerPort()+path+"/"; %> 学员列表
<% List> list=(List>)request.getAttribute("StudentList"); for(int i=0;i map=list.get(i); %> <%}%>
本文档为【servlet增删改查】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_954223
暂无简介~
格式:doc
大小:30KB
软件:Word
页数:11
分类:互联网
上传时间:2019-01-25
浏览量:21
学号: 姓名:
id 学号 姓名 性别 班级 年龄 住址 就读院校 联系方式 爱好
"/> <%=map.get("s_id")%> <%=map.get("s_number")%> <%=map.get("s_name")%> <%=map.get("s_sex")%> <%=map.get("s_class")%> <%=map.get("s_age")%> <%=map.get("s_add")%> <%=map.get("s_college")%> <%=map.get("s_mobile")%> <%=map.get("s_hobby")%>
添加