解决了此问题才算是高手!!!(高分结贴)

cavalry001 2003-06-15 11:15:00

一个web层程序,不如简单的登陆窗口,登陆之后,将用户的信息存于cookie或session当中,

然后从浏览器,采用webstart的方式,点击一个jnlp链接,启动GUI程序,也很简单,比如一个frame中内置一个文本框,
请问,GUI程序是否能够访问在web界面中保存的cookie或session信息,能否给个例子
(我还有一个附加的问题:对于web start技术,我看了"轻松玩转Java Web Start"
这篇文章,可以用google收到,试验之后,也成功了,不过对里面的JCE相关技术,知识不是很能够理解,各位大侠,给小第一个提示)。
...全文
24 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gongfucai 2003-06-17
  • 打赏
  • 举报
回复
学习
professional9344 2003-06-17
  • 打赏
  • 举报
回复
我是否有两颗星?
soyol 2003-06-17
  • 打赏
  • 举报
回复
难得呀!
wltsui 2003-06-17
  • 打赏
  • 举报
回复
up
KillAllError 2003-06-17
  • 打赏
  • 举报
回复
AllError
老兄
我叫KillAllError呵呵你完了
KillAllError 2003-06-17
  • 打赏
  • 举报
回复
5 4 3 2
轮到我就不用说话了
呵呵
wafer_w 2003-06-17
  • 打赏
  • 举报
回复
PF PF
pingcsdn 2003-06-17
  • 打赏
  • 举报
回复
哈哈,厉害
dooby 2003-06-16
  • 打赏
  • 举报
回复
楼上的,我也有同感
AllError 2003-06-16
  • 打赏
  • 举报
回复
五星级的亲自发言.我五条裤衩的就靠边站了
masterz 2003-06-16
  • 打赏
  • 举报
回复
http://www.rgagnon.com/javadetails/java-0092.html
Write/Read cookies using HTTP
For a Java-Javascript solution, check this How-to. // Changes by: Saar Machtinger, me@cawa.com
import java.net.*;
import java.io.*;
import java.util.*;

class CookiesInJava {
static Hashtable theCookies = new Hashtable();
/**
* Send the Hashtable (theCookies) as cookies, and write them to the specified URLconnection
*
* @param urlConn The connection to write the cookies to.
* @param printCookies Print or not the action taken.
*
* @return The urlConn with the all the cookies in it.
*/
public URLConnection writeCookies(URLConnection urlConn, boolean printCookies){
String cookieString = "";
Enumeration keys = theCookies.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
cookieString += key + "=" + theCookies.get(key);
if (keys.hasMoreElements())
cookieString += "; ";
}
urlConn.setRequestProperty("Cookie", cookieString);
if (printCookies)
System.out.println("Wrote cookies:\n " + cookieString);
return urlConn;
}

/**
* Read cookies from a specified URLConnection, and insert them to the Hashtable
* The hashtable represents the Cookies.
*
* @param urlConn the connection to read from
* @param printCookies Print the cookies or not, for debugging
* @param reset Clean the Hashtable or not
*/
public void readCookies(URLConnection urlConn, boolean printCookies,
boolean reset){
if (reset)
theCookies.clear();
int i=1;
String hdrKey;
String hdrString;
String aCookie;
while ((hdrKey = urlConn.getHeaderFieldKey(i)) != null) {
if (hdrKey.equals("Set-Cookie")) {
hdrString = urlConn.getHeaderField(i);
StringTokenizer st = new StringTokenizer(hdrString,",");
while (st.hasMoreTokens()) {
String s = st.nextToken();
aCookie = s.substring(0, s.indexOf(";"));
// aCookie = hdrString.substring(0, s.indexOf(";"));
int j = aCookie.indexOf("=");
if (j != -1) {
if (!theCookies.containsKey(aCookie.substring(0, j))){
// if the Cookie do not already exist then when keep it,
// you may want to add some logic to update the stored Cookie instead.
// thanks to rwhelan
theCookies.put(aCookie.substring(0, j),aCookie.substring(j + 1));
if (printCookies){
System.out.println("Reading Key: " + aCookie.substring(0, j));
System.out.println(" Val: " + aCookie.substring(j + 1));
}
}
}
}
}
i++;
}
}

/**
* Display all the cookies currently in the HashTable
*
*/
public void viewAllCookies() {
System.out.println("All Cookies are:");
Enumeration keys = theCookies.keys();
String key;
while (keys.hasMoreElements()){
key = (String)keys.nextElement();
System.out.println(" " + key + "=" +
theCookies.get(key));
}
}

/**
* Display the current cookies in the URLConnection, searching for the: "Cookie" header
*
* This is Valid only after a writeCookies operation.
*
* @param urlConn The URL to print the associates cookies in.
*/
public void viewURLCookies(URLConnection urlConn) {
System.out.print("Cookies in this URLConnection are:\n ");
System.out.println(urlConn.getRequestProperty("Cookie"));
}

/**
* Add a specific cookie, by hand, to the HastTable of the Cookies
*
* @param _key The Key/Name of the Cookie
* @param _val The Calue of the Cookie
* @param printCookies Print or not the result
*/
public void addCookie(String _key, String _val, boolean printCookies){
if (!theCookies.containsKey(_key)){
theCookies.put(_key,_val);
if (printCookies){
System.out.println("Adding Cookie: ");
System.out.println(" " + _key + " = " + _val);
}
}
}
}

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧