当前位置: 移动技术网 > IT编程>开发语言>Java > response对象的使用(实例讲解)

response对象的使用(实例讲解)

2019年07月19日  | 移动技术网IT编程  | 我要评论

1.使用response对象提供的sendredirect()方法可以将网页重定向到另一个页面。重定向操作支持将地址重定向到不同的主机上,这一点与转发是不同的。在客户端浏览器上将会得到跳转地址,并重新发送请求链接。用户可以从浏览器的地址栏中看到跳转后的地址。进行重定向操作后,request中的属性全部失效,并且开始一个新的request对象。

sendredirect()方法的语法格式如下:

response.sendredirect(string psth);

例子:新建一个index.jsp页面在body中添加java重定向语句

<%@ page language="java" contenttype="text/html;charset="utf-8" pageencoding="utf-8"%>
 
<html>
 
 <head>
 
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
 
  <title>首页</title>
 
 </head>
 
 <body>
 
  <%response.sendredirect("login.jsp");%>
 
 </body>
 
</html>

新建一个login.jsp 布局登录界面

<%@ page language="java" contenttype="text/html;charset=utf-8" pageencoding="utf-8"%>
<html>
 <head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title>用户登录页面</title>
 </head>
 <body>
  <form name="form1" method="post" action="">
 用户名:<input name="name" type="text" id="name" style="width:120px"><br>
 密 码:<input name="pwd" type="password" id="pwd" style="width:120px"><br>
 <input type="submit" name="submit" value="提交">
  </form>
 </body>
</html>

以上这篇response对象的使用(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网