📄 urlencode.jsp
字号:
<!-- Copyright (c) 1999-2002 by BEA Systems, Inc. All Rights Reserved.-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">
<meta name="description" content="BEA WebLogic Server">
<meta name="keywords" content="BEA WebLogic Server">
<title>HttpSessions and URL rewriting</title>
<LINK REL="stylesheet"
TYPE="text/css"
HREF="wls_examples.css"
TITLE="BEA WebLogic Server">
</head>
<body bgcolor="#ffffff" link="#3366cc" vlink="#9999cc" alink="#0000cc">
<!-- top intro paragraph tables -->
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="100%" bgcolor="#ff0000" height="1">
<p class="small"> </p>
</td>
</tr>
</table>
<table border=0 cellspacing="18" cellpadding="0">
<tr>
<td valign="top">
<a HREF="http://www.bea.com"><IMG SRC="images/logo_tm_onwt.jpg" alt="BEA Logo" border="0"></a>
<h3>HttpSessions and URL rewriting</h3>
</td>
</tr>
</table>
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="100%" bgcolor="#ff0000" height="1">
<p class="small"> </p>
</td>
</tr>
</table>
<table border=0 cellspacing="18" cellpadding="0">
<tr>
<td valign="top">
<p>
This servlet demonstrates how WebLogic deals with session-related
information when cookies are unavailable or disabled in your client's
browser. This is commonly referred to as "URL rewriting," because
instead of tracking the session ID in a cookie, WebLogic appends
the session ID at the end of the URL. <a href=#NOTE><b>NOTE</b></a>
<p>
To use this servlet to show how WebLogic rewrites URLs, you'll need
to set up both WebLogic and your browser.
<h4>
Check Deployment attributes
</h4>
<p> Make sure that the following attributes are defined in the <font
face="Courier New" size=-1>weblogic.xml</font> deployment
descriptor. For more information on editing Web Application deployment
descriptors, see <a href="http://e-docs.bea.com/wls/docs70/webapp/webappdeployment.html">Writing Web Application Deployment Descriptors</a>.
<p>
<table>
<tr>
<td>
<font face="Courier New"
size=-1>URLRewritingEnabled</font> set to true.
</td>
<td>
</td>
</tr>
</table>
<h4>
Set up your browser
</h4>
<p>
You must also <b>disable cookies</b> in your browser:
<dl>
<dt>
In Netscape
<dd>Select Preferences from the Edit menu.
<br>
On the Advanced tab panel, select the radio button beside "Disable Cookies".
<p>
<dt>In Internet Explorer
<dd>Select Internet Options from the View menu.
<br>
On the Advanced tab panel, scroll down to "Security".
<br>
Find the entry for "Cookies" and select the radio button
beside "Disable all cookie use".
</dl>
<h4>
Set some session info
</h4>
<p>
To see how it works, try setting some session name/value
pairs with cookies disabled. Session data will still be
stored on the server but the session ID will be passed to
the server by rewritten as arguments appended to the URL.
<p>
<b>Note:</b> You'll also need to encode the FORM ACTION
URL.
<p>
<%@ page import="
weblogic.common.T3Services
" %>
<%!
HttpSession session;
%>
<%
session = request.getSession(true);
if (session == null) {
out.print("\nSession is null!<p>");
}
if(session != null){
String url = "http://" + request.getServerName() + ":"
+ request.getServerPort() + request.getRequestURI();
out.print("The normal non-encoded URL is:<br><a href=\"" + url + "\">" + url + "</a><p>");
url = response.encodeURL(url);
out.print("The encoded URL is :<br><a href=\"" + url +
"\">" + url + "</a><p>");
}
if (request.getParameter("AddValue") != null) {
session.setAttribute("SessionServlet." + request.getParameter("NameField"),
request.getParameter("ValueField"));
} else if (request.getParameter("DeleteValue") != null) {
session.removeAttribute("SessionServlet." + request.getParameter("NameField"));
}
%>
<center>
<table border=1 cellspacing=2 cellpadding=5 width=400 bgcolor=#EEEEEE>
<th colspan=2><font face="Helvetica">Session : <%= session.getId() %></font><br>
</th>
<tr>
<th><font face="Helvetica"><B>Name</B></th>
<th><font face="Helvetica"><B>Value</B></th>
</tr>
<%
for (Enumeration e = session.getAttributeNames() ; e.hasMoreElements() ;) {
String attrName = (String)e.nextElement();
%>
<tr>
<td><font face="Helvetica"><%= attrName%></td>
<td><font face="Helvetica"><%= session.getAttribute(attrName) %></td>
</tr>
<%
}
%>
</table>
</center>
<p>
<form method="post" name="URLEncode" action="<%= response.encodeURL(request.getRequestURI()) %>">
<center>
<table border=1 cellspacing=2 cellpadding=5 width=400>
<th><font face="Helvetica">Name to add/delete</th>
<th><font face="Helvetica">Value</th>
<tr>
<td align=right><font face="Helvetica"><input type="text" name="NameField"></td>
<td align=left><font face="Helvetica"><input type="text" name="ValueField"></td>
</tr>
<tr>
<td colspan=2 align=center><input
type="submit" value=" Add " name="AddValue"><input type="submit" value="Delete" name="DeleteValue"></td>
</tr>
</table>
</center>
</form>
<a name="NOTE"></a>
For the very first request to a servlet
that involves a brand new HttpSession, the call
to <font face="Courier New" size=-1>response.encodeURL(url)</font> will always return
an encoded URL. This is because on the first
request there is no Session ID to be
found in either the Cookie or the URL. There is no
way to know if the browser has cookies turned
off. The course of action is:
<ol>
<li>Set a cookie.
<li>Encode URL with SessionCookie.
</ol>
<p>
If a cookie doesn't come back because cookies are
disabled, then the URL will contine to be
encoded with Session ID.
</td>
</tr>
</table>
<br>
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="100%" bgcolor="#ff0000" height="1">
<p class="small"> </p>
</td>
</tr>
</table>
<!-- FOOTER -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td align="left">
<p class="copyright">Last updated: March 2002</p>
</td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" border="0" width="100%"><!-- RED LINE -->
<tr>
<td width="100%" bgcolor="#ff0000" height="1">
<p class="small"> </p>
</td>
</tr>
</table>
<p class="copyright"><a href="http://www.bea.com">Home</a> |
<a href="http://www.bea.com/about/index.html" target="_top">Corporate Info</a> |
<a href="http://www.bea.com/press/index.html" target="_top">News</a> |
<a href="http://www.bea.com/solutions/index.html" target="_top">Solutions</a> |
<a href="http://www.bea.com/products/index.html" target="_top">Products</a> |
<a href="http://www.bea.com/partners/index.html" target="_top">Partners</a> |
<a href="http://www.bea.com/services.html" target="_top">Services</a> |
<a href="http://www.bea.com/events/index.html" target="_top">Events</a> |
<a href="http://www.bea.com/download.html" target="_top">Download</a> |
<a href="http://www.bea.com/purchase.html" target="_top">How to Buy</a>
<br>Copyright 2002, BEA Systems, Inc. All rights reserved.
<br>Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.
<br> <a href="http://www.bea.com/contact/index.html" target="_top">Contact BEA</a>
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -