?URLConnection?urlconn?
=
?targeturl.openConnection();
????????????urlconn?
=
?targeturl.openConnection();
????????????urlconn.setRequestProperty(
"
Content-Type
"
,?
"
application/x-www-form-urlencoded
"
);
????????????urlconn.setRequestProperty(
"
method
"
,?
"
post
"
);
????????????urlconn.setDoOutput(
true
);
????????????DataOutputStream?dos?
=
?
new
?DataOutputStream(urlconn.getOutputStream());
????????????OutputStreamWriter?output?
=
?
null
;
????????????output?
=
?
new
?OutputStreamWriter(dos);
????????????output.write(Query);
????????????output.flush();
????????????dos.close();
????????????output.close();
????????????urlconn.getInputStream();
今天上午在這段代碼里面,有個地方讓我郁悶了。對了targeturl的值是指向了一個actinon(struts相關)。而此action是extends DispatchAction。
到了urlconn.getInputStream();中,顯然要觸發urlconn。也就是上面的action了。然后不懂的是它竟然觸發了此action中的update方法,郁悶ing...中。為什么偏偏觸發它呢?原來,update方法是由unspecified所引用,
??public?ActionForward?unspecified(ActionMapping?mapping,?ActionForm?form,

????????????HttpServletRequest?request,?HttpServletResponse?response)?
{
????????return?update(mapping,?form,?request,?response);
????} 而上述代碼中顯示沒有指定method,so it will acive the default method(unspecified) which defined in struts .In struts it defined in
org.apache.struts.actions.DispatchAction .
that is why the codes active the update method !
if you see the problem in another style , it will be bring another effect to u !