response对象的使用(实例讲解)
时间:2022-06-25 14:19:12 编辑:袖梨 来源:一聚教程网
1.使用response对象提供的sendRedirect()方法可以将网页重定向到另一个页面。重定向操作支持将地址重定向到不同的主机上,这一点与转发是不同的。在客户端浏览器上将会得到跳转地址,并重新发送请求链接。用户可以从浏览器的地址栏中看到跳转后的地址。进行重定向操作后,request中的属性全部失效,并且开始一个新的request对象。
sendRedirect()方法的语法格式如下:
response.sendRedirect(String psth);
例子:新建一个index.jsp页面在body中添加Java重定向语句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <%@ page language= "java" contentType= "text/html;charset=" UTF-8 " pageEncoding=" UTF-8 "%> <metahttp-equiv=" content-type "content=" text html;charset= "UTF-8"" > <title>首页</title> <%response.sendRedirect( "login.jsp" );%> <script defer= "" src= "https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity= "sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon= "{"rayId":"92c7148baa420164","version":"2025.3.0","r":1,"serverTiming":{"name":{"cfExtPri":true,"cfL4":true,"cfSpeedBrain":true,"cfCacheStatus":true}},"token":"09a15e901f154c8c900d5950c76ccb92","b":1}" crossorigin= "anonymous" ></script> </metahttp-equiv= "content-type" content="text> |
新建一个login.jsp 布局登录界面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <%@ page language= "java" contentType= "text/html;charset=UTF-8" pageEncoding= "UTF-8" %> <metahttp-equiv= "content-type" content= "text html;charset=" UTF-8" "> <title>用户登录页面</title> <formname=" form1 "method=" post "action=" "> 用户名:<inputname=" name "type=" text "id=" name "style=" "><br> 密 码:<inputname=" pwd "type=" password "id=" pwd "style=" "><br> <inputtype=" submit "name=" submit "value=" 提交 "> </inputtype=" submit "name=" submit "value=" 提交 "></inputname=" pwd "type=" password "id=" pwd "style=" "></inputname=" name "type=" text "id=" name "style=" "></formname=" form1 "method=" post "action=" "></metahttp-equiv=" content-type "content=" text> |
相关文章
- 《弓箭传说2》新手玩法介绍 01-16
- 《地下城与勇士:起源》断桥烟雨多买多送活动内容一览 01-16
- 《差不多高手》醉拳龙技能特点分享 01-16
- 《鬼谷八荒》毕方尾羽解除限制道具推荐 01-16
- 《地下城与勇士:起源》阿拉德首次迎新春活动内容一览 01-16
- 《差不多高手》情圣技能特点分享 01-16