嘉兴高端网站天翼云 安装wordpress

diannao/2026/1/18 14:27:46/文章来源:
嘉兴高端网站,天翼云 安装wordpress,中国公关公司前十名,广州做网站哪家好【有道云笔记】十七 4.3 转发、重定向、Get、POST、乱码 https://note.youdao.com/s/GD5TRksQ 一、转发 转发#xff1a;一般查询了数据之后#xff0c;转发到一个jsp页面进行展示 req.setAttribute(list, list); req.getRequestDispatcher(student_lis…【有道云笔记】十七 4.3 转发、重定向、Get、POST、乱码 https://note.youdao.com/s/GD5TRksQ 一、转发 转发一般查询了数据之后转发到一个jsp页面进行展示 req.setAttribute(list, list); req.getRequestDispatcher(student_list.jsp).forward(req, resp); 二、重定向 重定向一般添加、删除、修改之后重定向到查找所有 resp.sendRedirect(/student); 重定向的状态码是302重定向的地址最终是由浏览器发送这个请求 给超链接添加点击事件并触发 a hrefjavascript:void(0) οnclickmethod()/a a hrefjavascript:; οnclickmethod()/a a hrefjavascript:method();xxx/a 三、Get 采用URL请求路径传输参数参数拼接在URL后面参数传输过程中隐私性较差直接在URL后面路径可以容纳的数据有限只能传递少量参数form表单请求默认就是get http://localhost:8080/student?methoddeleteByIdid23 http://localhost:8080/student?namezhangsanage12gender男 Get方式传参不是非得在form表单里面可以手动写在超链接的href里面直接在地址后面加?id2 四、POST 采用实体内容传参数参数在传输过程中不可见隐私性好实体内容专门用来传输数据大小没有限制使用在form上加methodpost 不管是Get方式还是POST方式传参数后台代码获取参数的方式都是一样的。 req.getParameter(name); 五、乱码问题总结 1、数据库创建时候选择utf-8编码 连接数据库url: jdbc:mysql://localhost:3306/java?useUnicodetruecharacterEncodingUTF-8 2、解决post请求乱码问题 methodpost req.setCharacterEncoding(UTF-8); 3、服务器响应浏览器的乱码问题 resp.setContentType(text/html;charsetutf-8); 六、前台往后台发请求方式 form表单超链接删除location.hrefajax 跳转到一个jsp页面的方式 直接访问这个jsp页面 http://localhost:8080/student_update.jsp访问servlet转发到这个页面 七、增删改查代码 //http://localhost:8080/index.jsp //http://localhost:8080/student WebServlet(/student) public class StudentServlet extends HttpServlet { //默认访问service Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //System.out.println(StudentServlet.service); //解决post请求乱码问题 req.setCharacterEncoding(UTF-8); // http://localhost:8080/student?methodselectAll // http://localhost:8080/student?methoddeleteByIdid23 String method req.getParameter(method); if (method null || method.equals()) { method selectAll; } switch (method) { case selectAll: selectAll(req, resp); break; case deleteById: deleteById(req, resp); break; case add: add(req, resp); break; case toUpdate: toUpdate(req, resp); break; case update: update(req, resp); break; } } private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException { System.out.println(StudentServlet.update); String id req.getParameter(id); String name req.getParameter(name); String age req.getParameter(age); String gender req.getParameter(gender); Connection connection null; PreparedStatement preparedStatement null; try { connection JDBCUtil.getConnection(); String sql update student set name?,age?,gender? where id?; preparedStatement connection.prepareStatement(sql); preparedStatement.setString(1, name); preparedStatement.setInt(2, Integer.parseInt(age)); preparedStatement.setString(3, gender); preparedStatement.setInt(4, Integer.parseInt(id)); System.out.println(preparedStatement); int count preparedStatement.executeUpdate(); System.out.println(count: count); } catch (SQLException throwables) { throwables.printStackTrace(); } resp.sendRedirect(/student); } private void toUpdate(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println(StudentServlet.toUpdate); String id req.getParameter(id); Connection connection null; PreparedStatement preparedStatement null; ResultSet resultSet null; Student student null; try { connection JDBCUtil.getConnection(); String sql SELECT id,name,age,gender FROM student where id?; preparedStatement connection.prepareStatement(sql); preparedStatement.setInt(1, Integer.parseInt(id)); System.out.println(preparedStatement); resultSet preparedStatement.executeQuery(); while (resultSet.next()) {//判断下一个有没有如果返回true而且指向下一个没有返回false //int id resultSet.getInt(id); String name resultSet.getString(name); int age resultSet.getInt(age); String gender resultSet.getString(gender); student new Student(Integer.parseInt(id), name, age, gender); } } catch (SQLException throwables) { throwables.printStackTrace(); } finally { JDBCUtil.close(connection, preparedStatement, resultSet); } //把list数据放到req里面 req.setAttribute(student, student); //转发到student_list.jsp页面进行展示 req.getRequestDispatcher(student_update.jsp).forward(req, resp); } private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException { System.out.println(StudentServlet.add); String name req.getParameter(name); String age req.getParameter(age); String gender req.getParameter(gender); Connection connection null; PreparedStatement preparedStatement null; try { connection JDBCUtil.getConnection(); String sql insert into student(name,age,gender) values(?,?,?); preparedStatement connection.prepareStatement(sql); preparedStatement.setString(1, name); preparedStatement.setInt(2, Integer.parseInt(age)); preparedStatement.setString(3, gender); System.out.println(preparedStatement); int count preparedStatement.executeUpdate(); System.out.println(count: count); } catch (SQLException throwables) { throwables.printStackTrace(); } finally { JDBCUtil.close(connection, preparedStatement, null); } resp.sendRedirect(/student?methodselectAll); } private void deleteById(HttpServletRequest req, HttpServletResponse resp) throws IOException { String id req.getParameter(id); Connection connection null; PreparedStatement preparedStatement null; try { connection JDBCUtil.getConnection(); String sql delete from student where id?; preparedStatement connection.prepareStatement(sql); preparedStatement.setInt(1, Integer.parseInt(id)); System.out.println(preparedStatement); int count preparedStatement.executeUpdate(); System.out.println(count: count); } catch (SQLException throwables) { throwables.printStackTrace(); } finally { JDBCUtil.close(connection, preparedStatement, null); } // /student 302 // 重定向 resp.sendRedirect(/student?methodselectAll); } private void selectAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Connection connection null; PreparedStatement preparedStatement null; ResultSet resultSet null; ListStudent list new ArrayList(); try { connection JDBCUtil.getConnection(); String sql SELECT id,name,age,gender FROM student; //预编译 preparedStatement connection.prepareStatement(sql); System.out.println(preparedStatement); resultSet preparedStatement.executeQuery(); while (resultSet.next()) {//判断下一个有没有如果返回true而且指向下一个没有返回false int id resultSet.getInt(id); String name resultSet.getString(name); int age resultSet.getInt(age); String gender resultSet.getString(gender); Student student new Student(id, name, age, gender); list.add(student); } for (Student student : list) { System.out.println(student); } } catch (SQLException throwables) { throwables.printStackTrace(); } finally { JDBCUtil.close(connection, preparedStatement, resultSet); } //把list数据放到req里面 req.setAttribute(list, list); //转发到student_list.jsp页面进行展示 req.getRequestDispatcher(student_list.jsp).forward(req, resp); } } student_list.jsp % page importcom.situ.web.pojo.Student % % page importjava.util.List % % page contentTypetext/html;charsetUTF-8 languagejava % html head titleTitle/title link relstylesheet hrefstatic/bootstrap-3.4.1-dist/css/bootstrap.css /head body % //JSP页面中可以嵌套Java代码 //JSP脚本在这里可以写任意的Java代码 //request、response:JSP页面的内置对象 ListStudent list (ListStudent) request.getAttribute(list); % a classbtn btn-primary href/student_add.jsp添加/a table classtable table-striped table-bordered table-hover table-condensed tr tdID/td td名字/td td年龄/td td性别/td td编辑/td td删除/td /tr % for (Student student : list) { % tr td%student.getId()%/td td%student.getName()%/td td%student.getAge()%/td td%student.getGender()%/td tda href/student?methodtoUpdateid%student.getId()%编辑/a/td %--/deleteStudent?id12 --% %--tda href/deleteStudent?id%student.getId()%删除/a/td--% %--tda href/student?methoddeleteByIdid%student.getId()%删除/a/td--% tda hrefjavascript:deleteById(%student.getId()%)删除/a/td /tr % } % /table script function deleteById(id) { var isDelete confirm(您确认要删除); if (isDelete) { location.href /student?methoddeleteByIdid id; } } /script /body /html student_add.jsp % page contentTypetext/html;charsetUTF-8 languagejava % html head titleTitle/title /head body form action/student?methodadd methodpost 用户名input typetext namename/br/ 年龄input typetext nameage/br/ 性别input typetext namegender/br/ input typesubmit value添加/ /form /body /html student_update.jsp % page importcom.situ.web.pojo.Student % % page contentTypetext/html;charsetUTF-8 languagejava % html head titleTitle/title /head body % Student student (Student) request.getAttribute(student); % form action/student?methodupdate methodpost input typehidden nameid value%student.getId()%/ 用户名input typetext namename value%student.getName()%/br/ 年龄input typetext nameage value%student.getAge()%/br/ 性别input typetext namegender value%student.getGender()%/br/ input typesubmit value修改/ /form /body /html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/90669.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

襄阳网站建设xytzg网站建设税率是多少

🍁 博客主页:江池俊的博客 💫收录专栏:C语言——探索高效编程的基石 💻 其他专栏:数据结构探索 💡代码仓库:江池俊的代码仓库 🎪 社区:C/C之家社区 🍁 如果觉…

福田商城网站建设wordpress后台登录路径

目录 泛型的理解: 在ArrayList中使用泛型: 在Map中使用泛型: 在接口中使用泛型: 自定义泛型类/接口与自定义泛型方法 自定义类/接口: 关于泛型类的子类: 注意点: 注意点: 自…

傻瓜式网站开发工具怎么在网站做视频接口

1.创建一个Navigation—based—Application项目,这样Interface Builder中会自动生成一个Table View,然后将Search Bar拖放到表示图上,以我们要给表示图添加搜索功能,不要忘记将Search Bar的delegate连接到File‘s Owner项&#xf…

wordpress网站部署建外贸企业网站

YOLO水稻病害识别/分类数据集,包含疾病和正常2类,共2000多张图像,yolo标注完整,可直接训练。 适用于CV项目,毕设,科研,实验等 需要此数据集或其他任何数据集请私信

.net 网站模板下载地址友链查询站长工具

一、前言 在检索增强生成(Retrieval-Augmented Generation, RAG)的框架下,重排序(Re-Rank)阶段扮演着至关重要的角色。该阶段的目标是对初步检索得到的大量文档进行再次筛选和排序,以确保生成阶段能够优先…

学网站开发多少钱宁波网站制作网站

一、SQLPlus查询的结果,可以根据自己的屏幕情况进行调节:我们知道sqlplus模式下,select查询的时候经常会遇到返回的记录折行,这时候我们往往会设置行宽,列宽和页面记录。设置行宽:set linesize 200 表示行宽被设置为20…

一级a做爰全过程网站网站图片展示源代码

目录 1、TypeScript 接口 1.1、实例 1.2、联合类型和接口 1.3、接口和数组 1.4、接口和继承 1.5、单继承实例 1.6、多继承实例 2、TypeScript 对象 2.2、对象实例 2.3、TypeScript类型模板 2.4、鸭子类型(Duck typing) 1、TypeScript 接口 接口…

企业百度网站怎么做wordpress又拍云cdn伪静态

FluentAspects -- 基于 Fluent API 的 AopIntro上次我们做了一个简单的 AOP 实现示例,但是实现起来主要是基于 Attribute 来做的,对于代码的侵入性太强,于是尝试实现基于 Fluent API 的方式来做 AOP 。抽象 InterceptorResolver原来获取方法执…

时尚杂志网站设计分析软件技术外包是什么行业

▪查看某目录下所有文件的个数:[rootlocalhost1 opt]# ls -l |grep "^-"|wc -l▪查看某目录下所有文件的个数,包括子目录里面的:[rootlocalhost1 opt]# ls -lR|grep "^-"|wc -l▪查看某目录下文件夹(目录)的个数&#xf…

陕西住房与城乡建设部网站网络优化有哪些主要流程

问题: 路由传参一直不能获取到参数, 未出现报错 原因: 混淆 query 和 params 的使用方法, 在使用 params 传参时错误的使用了 path 代码: 正确写法1: 使用path要对应query ...this.$router.push({path: /Health,query: {title:…

如何做网站内页排名详细网站设计需求表

文章目录 深度生成模型之GAN基础生成对抗网络1. 生成对抗网络如何生成数据2. 生成对抗原理3. GAN的核心优化目标4. D的优化5. GAN的理想状态6. GAN的训练7. 梯度不稳定与模式崩塌(collapse mode)问题8. 梯度消失问题 深度生成模型之GAN基础 生成对抗网络 1. 生成对抗网络如何…

xyz溢价域名最好的网站网站建设一点通

相信很多博友在开发初次接触学习C# winForm时,当窗体大小变化时,窗体内的控件并没有随着窗体的变化而变化,最近因为一个项目工程的原因,也需要解决这个问题。通过查阅和学习,这个问题得到了解决,或许不是很…

服务器 空间 虚拟主机 网站需要低价网站建设新闻

搜索算法例子 搜索算法是计算机科学中的重要部分,用于在数据集合中查找特定元素。这些搜索算法在不同场景中有不同的应用和性能表现,通过选择合适的搜索算法,可以提高程序的性能和效率。线性搜索:适用于小型、无序数据集。二分搜索:适用于大型、有序数据集。深度优先搜索(…

徐州祥云做网站网站空间排名

本文转载自公众号 PaperWeekly, 对我们近期的论文浅尝进行了精选整理并附上了相应的源码链接,感谢 PaperWeekly!TheWebConf 2018■ 链接 | https://www.paperweekly.site/papers/1956■ 解读 | 花云程,东南大学博士,研究方向为自然…

连云港建设部网站自做美食哪些网站

一、工程问题与学术研究的常规融合方法 工程问题与学术研究的融合通常体现在“产学研结合”的模式中,具体策略如下: 1. 需求导向:从实际工程问题出发,明确科研目标。在解决工程问题的过程中,识别出需要进一步研究的基…

网站建设课程设计报告总结网站的管理包括

场景 业务上有许多发送邮件的场景,发送的邮件基本上都是自动发送的,而且邮件内容是很重要的,对于邮件发没发送,发送的时间点对不对每次回归测试工作量太大了,所以考虑把这部分内容加入到自动化测试中 工具 python g…

东坑网页设计东莞seo网络营销策划

vue中keep-alive组件主要有三个常用的props。 1,include存放的name是组件自身的name属性,只有名称匹配的组件会被缓存2,exclude,任何名称匹配的组件都不会被缓存3,max,最多可以缓存多少组件实例&#xff0…

网站内容上传要求中天钢铁 网站建设

使用腾讯云服务器搭建网站全流程,包括轻量应用服务器和云服务器CVM建站教程,轻量可以使用应用镜像一键建站,云服务器CVM可以通过安装宝塔面板的方式来搭建网站,腾讯云服务器网txyfwq.com整理使用腾讯云服务器建站教程,…

网上停车场做施工图人员网站内蒙古赤峰市信息网官网

点击此处查看原题​​​​​​​ *思路:首先要求 00 11 尽可能的多,所以尽可能多的多配对,配对只在i , i 1之间发生,所以只需要关注str[i] 和 str[i 1]即可,如果str[i] str[i 1] ,那么一定配对&#x…

怎么建个废品网站投资建设网站

一、前言这几年前端的发展速度就像坐上了火箭,各种的框架一个接一个的出现,需要学习的东西越来越多,分工也越来越细,作为一个 .NET Web 程序猿,多了解了解行业的发展,让自己扩展出新的技能树,对…