首頁  >  文章  >  Java  >  java webstart問題怎麼解決

java webstart問題怎麼解決

王林
王林轉載
2023-05-16 19:07:041184瀏覽

當時碰到的幾個技術問題是:

1.從web傳遞相關的參數給application,

  解決方法:用動態jnlp檔(jsp實作jnlp),同時使用如下傳參方法

application-desc Element

The application element indicates that the JNLP file is launching an application ( as opposed to an applet). The application element has an optional attribute, main-class, which can be used to specify the name of the application's main class, i.e., the class that contains the  static void main(String argv[]) method where execution must begin.

The 

main-class attribute can be omitted if the first JAR file specified in the JNLP file contains a manifest file containing the main class.

Arguments can be specified to the application by including one or more nested 

argument elements. For example:

#argument

 elements. For example:argument
<application-desc main-class="Main">
<argument>arg1argument>
#<argument>arg2argument>

application-desc>

2.如何處理application的結果傳回給web server

解決方法,用URLConnection結合從jnlp中傳來的web url (為一個後台處理的servlet地址),sessionID(用於識別當前用戶,權限等判斷)去創建一個新的url對象,並透過它在ap​​plication和web server之間傳遞資料。在後台的servlet中透過sessionid,從session listener中找到目前用戶,

  private String getStringPostRequest(String command) throws Exception {
DataOutputStream dos=null;
InputStream dis=null;##DataOutputStream dos=null;
InputStream dis=null;# #try {
URLConnection urlConn = new URL(webServerStr).openConnection();
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
urlConn.setAllowUserInteraction(false);

urlConn.setUseCaches(false);

urlConn.setRequestProperty(
"Content-Type",
"application/x-www-form-urlencoded");

dos = new DataOutputStream(urlConn.getOutputStream());
dos.writeBytes(command "&sessionId=" this.sessionId);
dos.close();
// read input from servlet
dis =
new ObjectInputStream(urlConn.getInputStream());
String ret = dis.readObject().toString();
dis.close();
return ret;
} catch (Exception e) {
throw e;
} finally{

if ( dos!=null) dos.close();

if ( dis!=null) dis.close();

}

}

後台sevlet:

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{##HttpSession#Httion ();
System.out.println("Application:" hSession.getId());

if(MyListener.getSessionById(request.getParameter("sessionId")) != null)

hSession = MyListener.getSessionById(request.getParameter("sessionId"));

System.out.println("OK" hSession);

##..............}

sessionlistener:

import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContextEvent;

import javax.servlet.ServletContextListener ;

import javax.servlet.http.*;

public class SessionsListener

implements ServletContextListener, HttpSessionListener

{

static Map map = new HashMap();
#{

static Map map = new HashMap();


public SessionsListener()
{

}


public void contextInitialized(ServletContextEvent servletcontextevent)
{

#}

##public void contextDestroyed(ServletContextEvent servletcontextevent)
{
}

public void sessionCreated(HttpSessionEvent httpsessionevent)

{

HttpSession httpsession = httpsessionevent.getSession();
map.put(httpsession.getId(), httpsession);
}

public void sessionDestroyed(HttpSessionEvent httpsessionevent)

{

HttpSession httpsession = httpsessionevent.getSession();
map.remove(httpsession.getId());
}

public static HttpSession getSessionById(String s)

{

return (HttpSession)map.get(s);

}

#}

3.jar包數位簽章問題

4.java webstart cache問題即:JNLP file caching

#http://forum.java.sun.com/thread.jspa?forumID =38&threadID=556847

(1)

If you remove the href= parameter from the jnlp tag, Java Web Start 1.4.2 will not cache the jnlp file.

1.5.0 still will, but if you also remove the

(2)

It seems the issue is with generated JNLP files.

Try the following:

# response.addDateHeader("Date", Calendar.getInstance().getTime().getTime());###response.addDateHeader("Last-Modified", Calendar.getInstance().getTime().getTime()) ;######Seems to have solved the problem for us.###

以上是java webstart問題怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除