您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“java webstart”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“java webstart”吧!
最近做了一個(gè)java webstart的項(xiàng)目,java webstart用起來很簡單,在做的過程中,也碰到些技術(shù)性的問題。比如如何生成動態(tài)的jnlp等問題,在解決相關(guān)問題的同時(shí),在解決問題的時(shí)候,查看最多的還是官方提供的文檔及資料,以及到sun的webstart上找到相關(guān)的解決辦法,
當(dāng)時(shí)碰到的幾個(gè)技術(shù)問題是:
1.從web傳遞相關(guān)的參數(shù)給application,
解決辦法:用動態(tài)jnlp文件(jsp實(shí)現(xiàn)jnlp),同時(shí)用到如下傳參辦法
application-desc
ElementThe 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 public 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 themain
class.Arguments can be specified to the application by including one or more nested argument elements. For example:
<application-desc main-class="Main">
<argument>arg1argument>
<argument>arg2argument>
application-desc>
2.如何將application處理的結(jié)果傳回給web server
解決辦法,用URLConnection結(jié)合從jnlp中傳來的web url (為一個(gè)后臺處理的servlet地址),sessionID(用于識別當(dāng)前用戶,權(quán)限等判斷)去創(chuàng)建一個(gè)新的url對象,并通過它在application和web server之間傳遞數(shù)據(jù)。在后臺的servlet中通過sessionid,從session listener中找到當(dāng)前用戶,
private String getStringPostRequest(String command) throws Exception {
DataOutputStream dos=null;
ObjectInputStream 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 hSession = request.getSession();
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();
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包數(shù)字簽名問題
http://www-900.ibm.com/developerWorks/cn/java/l-webstart/index.shtml
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.
下面是幾個(gè)webstart的資料網(wǎng)址:
http://www-900.ibm.com/developerWorks/cn/java/l-webstart/index.shtml
http://java.sun.com/j2se/1.4.2/docs/guide/jws/developersguide/contents.html
http://forum.java.sun.com/forum.jspa?forumID=38
到此,相信大家對“java webstart”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。