本篇內(nèi)容主要講解“java webstart”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“java webstart”吧!
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到順城網(wǎng)站設(shè)計(jì)與順城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)頁(yè)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋順城地區(qū)。最近做了一個(gè)java webstart的項(xiàng)目,java webstart用起來(lái)很簡(jiǎn)單,在做的過(guò)程中,也碰到些技術(shù)性的問(wèn)題。比如如何生成動(dòng)態(tài)的jnlp等問(wèn)題,在解決相關(guān)問(wèn)題的同時(shí),在解決問(wèn)題的時(shí)候,查看最多的還是官方提供的文檔及資料,以及到sun的webstart上找到相關(guān)的解決辦法,
當(dāng)時(shí)碰到的幾個(gè)技術(shù)問(wèn)題是:
1.從web傳遞相關(guān)的參數(shù)給application,
解決辦法:用動(dòng)態(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中傳來(lái)的web url (為一個(gè)后臺(tái)處理的servlet地址),sessionID(用于識(shí)別當(dāng)前用戶,權(quán)限等判斷)去創(chuàng)建一個(gè)新的url對(duì)象,并通過(guò)它在application和web server之間傳遞數(shù)據(jù)。在后臺(tái)的servlet中通過(guò)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();
}
}
后臺(tái)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ù)字簽名問(wèn)題
http://www-900.ibm.com/developerWorks/cn/java/l-webstart/index.shtml
4.java webstart cache問(wèn)題即: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
到此,相信大家對(duì)“java webstart”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
網(wǎng)站題目:javawebstart-創(chuàng)新互聯(lián)
本文來(lái)源:http://jinyejixie.com/article28/gppjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、服務(wù)器托管、標(biāo)簽優(yōu)化、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)公司、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容