软件编程
位置:首页>> 软件编程>> java编程>> response对象的使用(实例讲解)

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

作者:jingxian  发布时间:2023-11-30 12:23:22 

标签:response,对象

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>

来源:http://www.cnblogs.com/lihuibin/archive/2017/08/31/7460153.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com