java - Accessing JSF session scoped bean from servlet which is called by applet embedded in JSF webapp -


i need access session scoped bean servlet. tried

userbean userbean = (userbean) request.getsession().getattribute("userbean"); 

as described in post. null result, altough instance of userbean alreay instatiated. annotations/imports use userbean :

import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped;  @managedbean @sessionscoped public class userbean implements serializable{  ... } 

some background why can't rid of servlet : have file upload applet in jsf page. applet expects adress can send it's post request. (i can't edit post request add more fields or something). post method of servlet stores file. job can't done managed bean because servlet has annotated @multipartconfig , can't add annotation jsf managed bean.

if returns null, can mean 2 things:

  1. jsf hasn't created bean beforehand yet.
  2. the applet-servlet interaction doesn't use same http session webapp.

given way how described functional requirement, think it's latter. need ensure pass session identifier of webapp along http request applet well. can in form of jsessionid cookie or jsessionid url path attribute.

first, need tell applet session id webapp using. can passing parameter <applet> or <object> tag holding applet

<param name="sessionid" value="#{session.id}" /> 

(the #{session} implicit jsf el variable referring current httpsession in turn has getid() method; don't need create managed bean or so, above line of code complete as-is)

which can retrieved in applet follows:

string sessionid = getparameter("sessionid"); 

you didn't describe how you're interacting servlet, assuming you're using standard java se urlconnection this, pointing @webservlet("/servleturl") servlet, can use setrequestproperty() set request header:

url servlet = new url(getcodebase(), "servleturl"); urlconnection connection = servlet.openconnection(); connection.setrequestproperty("cookie", "jsessionid=" + sessionid); // ... 

alternatively, can pass url path attribute:

url servlet = new url(getcodebase(), "servleturl;jsessionid=" + sessionid); urlconnection connection = servlet.openconnection(); // ... 

(please note case matters in both cases)

either way, way applet-servlet interaction take place in same http session jsf managed beans.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -