Home >Java >javaTutorial >How to solve java webstart problem
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## 2. How to process the results of application Pass it back to the web serverThe 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 {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 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>
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.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();
}
}
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);
import java.util.Map;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener ;
import javax.servlet.http.*;
implements ServletContextListener, HttpSessionListener
{
{
}
{
}
{
}
{
HttpSession httpsession = httpsessionevent.getSession();
map.put(httpsession.getId(), httpsession);
}
{
HttpSession httpsession = httpsessionevent.getSession();
map.remove(httpsession.getId());
}
{
return (HttpSession)map.get(s);
}
3.jar package digital signature issue4.java webstart cache issue: JNLP file cachinghttp://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
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!