Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess session in servlet applet communication
    text
    copied!<p>I have session problem in developing the servlet applet communication program. I have login page in jsp after successful login of user i am guiding the user to a index.jsp page which has an applet. I have set a session variable in servlet before redirecting to index.jsp. In my applet i have to get the data stetted in session and some data from databse and properties file. my code is<br> //Servlet</p> <pre><code>if(action.equals("login")){ uinfo = new UserInformation(); String uid = request.getParameter("txt_UserName"); String pwd = request.getParameter("pwd_PassWord"); int i = uinfo.authenticateUser(uid, pwd); //System.out.println(i); if(i==1){ session.setAttribute("uName", uid); request.getRequestDispatcher("index.jsp").forward(request, response); else if(action.equals("applet")){ try{ output = new ObjectOutputStream(response.getOutputStream()); uinfob= new UserInformationBean(); Properties prop = new Properties(); try { prop.load(new FileInputStream(path+"/connection.properties")); } catch (IOException ex) { ex.printStackTrace(); } uinfob.setHost(prop.getProperty("host")); uinfob.setIs_Active("Y"); uinfob.setUid(session.getAttribute("uName").toString()); output.writeObject(uinfob); output.flush(); //output.close(); }catch(IOException iox){ iox.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ output.close(); } } </code></pre> <p>In my applet</p> <pre><code>public void init() { try{ String queryString="action=applet"; URL codeBase = getCodeBase(); URL servletURL = new URL(codeBase.getProtocol(), codeBase.getHost(), codeBase.getPort(), "/SwingBrowser1/UserServlet?"+queryString); servletConnection = servletURL.openConnection(); servletConnection.setDoInput(true); servletConnection.setDoOutput(true); servletConnection.setUseCaches(false); servletConnection.setDefaultUseCaches(false); servletConnection.setRequestProperty("Content-Type","application/octet-stream"); getData(); }catch(Exception e){ e.printStackTrace(); } } // TODO overwrite start(), stop() and destroy() methods public void getData() { try{ ObjectInputStream input = new ObjectInputStream(servletConnection.getInputStream()); UserInformationBean uib =(UserInformationBean)input.readObject(); System.out.println(uib.getHost()+"-------------"+uib.getIs_Active()+"-----------------"+uib.getUid()); input.close(); } catch( Exception e) { e.printStackTrace(); } </code></pre> <p>It is getting java.io.EOFException error and i tested this with a sop in my else block of servlet. The attribute which i set before is returning null value.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload