This content has been marked as final.
Show 2 replies
-
1. Re: How to submit jsf page from applet with HttpURLConnectio
nbelaevski May 1, 2009 7:25 AM (in response to jadtn)Hello,
JSF needs several service parameters to be passed to Faces Servlet. Check all form fields. -
2. Re: How to submit jsf page from applet with HttpURLConnectio
jadtn May 2, 2009 7:17 AM (in response to jadtn)Ok thanks i found :
1-First you need the jsessionid,if you don t have create a connexion :private static final String REG_EXPR_JSESSIONID = "jsessionid=[^\"]+"; private static final String REG_EXPR_ACK="ackmsg[0-9]+"; public static final Pattern patternSession = Pattern.compile(REG_EXPR_JSESSIONID); public static String createSessionID(String jsfpath) throws MalformedURLException, IOException{ URLConnection urlConnection = new URL(jsfpath).openConnection(); urlConnection.setDoOutput(true); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String jid =null;// catsession(in); String form=null; while ((form = in.readLine()) != null && jid==null){ Matcher m = patternSession.matcher(form); if(m.find()){ jid=m.group(); } } in.close(); return jid; }
2-send the request, becarefull at 2 things :
a) the url must contains the jsessionid like :http://localhost/mypage.jsf;jsessionid=XXXXX
b) pass the view state in request params like javax.faces.ViewState=j_id1
For me i already send j_id1 and i ve got the value when i call the page for the first time, you need to change it.Map<String, String[]> params=new Hashtable<String, String[]>(); params.put("chat", new String[]{"chat"}); params.put("chat:msg", new String[]{"BRAVOOOOOOOOOOOOOOOOOO"}); params.put("chat:send", new String[]{""}); params.put("chat:msgid", new String[]{"464"}); params.put("javax.faces.ViewState", new String[]{"j_id1"}); InputStream is = doPost("http://localhost:8080/testchat.jsf;"+jsessionid, params); is.close();
I ve got the method doPost from here :
http://balusc.blogspot.com/2006/05/httpservletutil.html#doPost