通过httpclient post方法访问struts2的action,找不到指定的action
struts.xml配置<package name="rest" extends="rest-default" namespace="/rest">
<action name="payment" class="com.greatmay.webapp.action.PaymentInfoAction">
</action>
PaymentInfoAction主要方法
public void notifyResult(){
String content = writeRequestXml(getRequest().getInputStream());
}
/**
* 获取请求信息
* @param is
* @return
* @throws Exception
*/
private String writeRequestXml(InputStream is) throws Exception {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
StringBuffer sb = new StringBuffer();
String sTempOneLine = new String("");
// 加上"\n"保留客户端的数据格式
while ((sTempOneLine = br.readLine()) != null) {
sb.append(sTempOneLine + "\n");
}
String reqContent = sb.toString();
System.out.println("request content:" + reqContent);
return reqContent;
} catch (Exception e) {
throw e;
}
}
httpclient方法
static String path ="ip:port/rest/payment!notifyResult";
HttpClient HttpClent = new HttpClient();
PostMethod peostMethod = new PostMethod(path);
String respStr=peostMethod.getResponseBodyAsString(); struts2 --------------------编程问答-------------------- 服务端报java.lang.NullPointerException --------------------编程问答-------------------- 进action方法了吗? --------------------编程问答-------------------- 后来通过debug查到没有找到方法,将方法名改为prepareNotifyResult()这个就能进入action了
补充:Java , Java EE