Home  >  Article  >  Java  >  How to solve java webstart problem

How to solve java webstart problem

王林
王林forward
2023-05-16 19:07:041184browse

Several technical problems encountered at that time were:

1. Pass relevant parameters from the web to the application,

Solution: Use dynamic jnlp files (jsp to implement jnlp), and at the same time The following parameter passing method is used

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. How to process the results of application Pass it back to the web server

The solution is to use URLConnection combined with the web url passed from jnlp (a servlet address for background processing) and sessionID (used to identify the current user, permissions, etc.) to create a A new url object, through which data is passed between the application and the web server. In the background servlet, find the current user from the session listener through the sessionid,

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();
}
}

Background 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 package digital signature issue

4.java webstart cache issue: 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.

The above is the detailed content of How to solve java webstart problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete