JSP:请求数据和请求本身的一些信息

来源:互联网 发布:宽带网络那家好 编辑:程序博客网 时间:2024/04/28 15:54

JSP:请求数据和请求本身的一些信息

jsp 隐式对象 赵振江

隐式对象

描述

编写一个JSP登录页面,可输入用户名和密码,提交请求到另一个JSP页面,该JSP页面获取请求的相关数据并显示出来。请求的相关数据包括用户输入的请求数据和请求本身的一些信息(比如请求使用的协议getProtocol() 、请求的URI request.getServletPath() 、请求方法request.getMethod() 、远程地址request.getRemoteAddr()等)。

output.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><form action="output.jsp" method="post"> 用户名:<input type="text" name="user"><br> 密 码:<input type="password" name="pwd"><br><button type="submit" >提交</button></form></body></html>

input.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%>">        <title>My JSP 'output.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">        <!--    <link rel="stylesheet" type="text/css" href="styles.css">    -->    </head>    <body>        <%    String user=request.getParameter("user");    String pwd=request.getParameter("pwd").hashCode()+"";     %>        用户名:<%=user %><br>        用户名:<%=pwd %><br>        请求使用协议:<%=request.getProtocol() %><br>        请求的URL:<%=request.getServletPath() %><br>        远程地址:<%=request.getRemoteAddr() %><br>        请求方法:<%=request.getMethod() %><br>    </body></html>

一张图片说明过程

0 0
原创粉丝点击