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 !