JSP内置对象---get和post对象

来源:互联网 发布:java技术面试 编辑:程序博客网 时间:2024/05/29 16:13

这里写图片描述
下面是一个小例子
先以get方式提交:
Login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"    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=ISO-8859-1"><title>Insert title here</title></head><body>    <h1>用户登入</h1>    <hr>    <form action="dologin.jsp" name = "loginForm" method = "get">        <table>            <tr>                <td>                    用户名:                </td>                <td>                    <input type = "text" name = "uesrname"/>                </td>            </tr>            <tr>                <td>                    密码:                </td>                <td>                    <input type = "password" name = "password"/>                </td>            </tr>            <tr>                <td colspan = "2">                    <input type = "submit" value = "登入" />                </td>            </tr>        </table>    </form></body></html>

dologin.jsp这里我们不对用户信息做处理

<%@ page language="java" contentType="text/html; charset=utf-8"    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=ISO-8859-1"><title>Insert title here</title></head><body>    <h1>登入成功</h1></body></html>

这里写图片描述
我们可以看到登入成功之后地址栏上会显示用户信息,所以get方式安全性不高。
在以post方式提交:

<%@ page language="java" contentType="text/html; charset=utf-8"    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=ISO-8859-1"><title>Insert title here</title></head><body>    <h1>用户登入</h1>    <hr>    <form action="dologin.jsp" name = "loginForm" method = "post">        <table>            <tr>                <td>                    用户名:                </td>                <td>                    <input type = "text" name = "uesrname"/>                </td>            </tr>            <tr>                <td>                    密码:                </td>                <td>                    <input type = "password" name = "password"/>                </td>            </tr>            <tr>                <td colspan = "2">                    <input type = "submit" value = "登入" />                </td>            </tr>        </table>    </form></body></html>

这里写图片描述
我们可以看到同样登入成功,单地址栏并未显示用户信息,所以post方式较get方式更安全