码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-04-26 10:55:05      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

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>

一张图片说明过程

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

标签:

原文地址:http://blog.csdn.net/c_major/article/details/45286143

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!