成都创新互联网站制作重庆分公司

javawebstart

本篇内容主要讲解“java webstart”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“java webstart”吧!

十余年的万宁网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整万宁建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“万宁网站设计”,“万宁网站推广”以来,每个客户项目都认真落实执行。

最近做了一个java webstart的项目,java webstart用起来很简单,在做的过程中,也碰到些技术性的问题。比如如何生成动态的jnlp等问题,在解决相关问题的同时,在解决问题的时候,查看最多的还是官方提供的文档及资料,以及到sun的webstart上找到相关的解决办法,

当时碰到的几个技术问题是:

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 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 the main 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处理的结果传回给web server

解决办法,用URLConnection结合从jnlp中传来的web url (为一个后台处理的servlet地址),sessionID(用于识别当前用户,权限等判断)去创建一个新的url对象,并通过它在application和web server之间传递数据。在后台的servlet中通过sessionid,从session listener中找到当前用户,

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包数字签名问题

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 theit will not mater, since you will not be able to launch it from a shortcut or from the Cache Viewer.

(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.

下面是几个webstart的资料网址:

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”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


新闻标题:javawebstart
链接地址:http://cxhlcq.com/article/iiojdj.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部