jsp response.sendRedirect()用法详解
更新时间:2021-10-24 03:28:38 作者:佚名 我要评论(0)
response和request一样都是jsp内置对象,request是获取用户的请求,response处理用户请求。sendRedirect()函数的作用是重定向
sendRedirect()
response和request一样都是jsp内置对象,request是获取用户的请求,response处理用户请求。sendRedirect()函数的作用是重定向网页,向浏览器发送一个特殊的Header,然后由浏览器来做重定向,转到指定的页面。下面我将创建四个页面,首先是sex.jsp,有一个下拉列表和提交按钮确定,选择“男”,就跳转到male.jsp,选择“女”就跳转到female.jsp,中间通过sex_action.jsp进行重定向
<!-- sex.jsp --> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" > <title>Sex Select's page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> </head> <body> <form action="<%=basePath%>c03/sex_action.jsp" method="post"> <select name="sex"> <option>男</option> <option>女</option> </select> <button type="submit">提交</button> </form> </body> </html>
<!-- sex_action.jsp --> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" > <title>My JSP 'sex_action.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> </head> <body> <% request.setCharacterEncoding("UTF-8"); String sex = request.getParameter("sex"); out.println(sex); if("男".equals(sex)) { response.sendRedirect("male.jsp"); return; } else if("女".equals(sex)) { response.sendRedirect("female.jsp"); return; } %> </body> </html>
到此这篇关于jsp response.sendRedirect()用法详解的文章就介绍到这了,更多相关jsp response.sendRedirect()内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
- response.setContentType()参数以及作用详解
- Response.AddHeader案例讲解
- 如何使用spring ResponseEntity处理http响应
- jsp Response对象页面重定向、时间的动态显示
- JavaWeb入门:HttpResponse和HttpRequest详解
- Flask response响应的具体使用
- ResponseBodyAdvice踩坑及解决
- 基于@RequestBody和@ResponseBody及Stringify()的作用说明
您可能感兴趣的文章:
相关文章
jsp response.sendRedirect()用法详解
sendRedirect() response和request一样都是jsp内置对象,request是获取用户的请求,response处理用户请求。sendRedirect()函数的作用是重定向2021-10-24使用注解@Validated和BindingResult对入参进行非空校验方式
目录注解@Validated和BindingResult对入参非空校验@Validated 和 BindingResult 使用遇到的坑注解@Validated和BindingResult对入参非空校验2021-10-24Java构造方法 super 及自定义异常throw合集详解用法
1.构造方法: public 类名(){} 区别一下 // public void 方法名(){} 分为有参,无参子类构造方法 public class Zi extends fu{ pu2021-10-24如何在SpringBoot+Freemarker中获取项目根目录
目录在Freemarker中获取项目根目录Freemark模板引擎路径的几种设置方法在SpringMVC中我们想返回视图是怎么做的在SpringBoot中springboot不推2021-10-24Java常用API类之Math System tostring用法详解
1.注意(类名不能与math重名,否则可能报错误) 1.math:可以直接拿来用的接口类 Math.abs(-90);返回参数的绝对值 Math.max(60,98)返回参数2021-10-24
最新评论