Struts2:动作以递增方式多次执行

时间:2013-12-30 16:16:43

标签: java android tomcat struts2

我正在使用 Struts 2.3.16与Tomcat 7.0.47 来处理计算机上的请求。这些请求由 Android应用程序以下列方式发送: -

    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    HttpPost httppost = new HttpPost("http://--my server IP--:port/webAppName/struts-action-name");
    httppost.setEntity(new UrlEncodedFormEntity(Data_To_Be_Sent));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();

但是,在服务器端,我注意到动作类的执行次数越来越多。例如,在tomcat上部署webapp后,对于我的Android应用程序发送的第一个请求,struts的action类会被执行一次(应该如此)。 对于第二个请求,操作类执行两次,对于第三个请求,它将执行三次,依此类推......

我写的是 struts'动作类: -

public class GetTagsAction extends ActionSupport {
/**
 * 
 */
private static final long serialVersionUID = 1L;
private KrozonaLogger logger = new KrozonaLogger(this.getClass());
public String magazineName;
public InputStream inputStream;
public String xmlStream;
public byte[] incomingImageByte;
public String image;


public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
    toImageByte();
}

public String getMagazineName() {
    return magazineName;
}

public void setMagazineName(String magazineName) {
    this.magazineName = magazineName;
    logger.log("Magazine Name is: " + this.magazineName);
}

public byte[] getIncomingImageByte() {
    return incomingImageByte;
}

public void toImageByte() {
    this.incomingImageByte = Base64.decodeBase64(image);
    logger.log("Number of elements in incomingImage byte array: " + incomingImageByte.length);
}

public String getXmlStream() {
    return xmlStream;
}

public String execute() {
    try {
        this.xmlStream = DBAccessService.getXml(magazineName, incomingImageByte);
        if (xmlStream != null) {
            this.inputStream = IOUtils.toInputStream(xmlStream);
            return "success";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "failure";
}

public InputStream getInputStream() {
    return inputStream;
}
}

这是显示奇怪行为的日志: -

<---- for first request ----->
INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Number of elements in incomingImage byte array: 71739
INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Magazine Name is: Maxim
INFO - class com.krozona.databaseaccess.service.DbService: Couldn't find a match for the input image


<---- for second request ----->
INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Number of elements in incomingImage byte array: 71458
INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Number of elements in incomingImage byte array: 71458
INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Magazine Name is: Maxim
INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Magazine Name is: Maxim
INFO - class com.krozona.databaseaccess.service.DbService: Couldn't find a match for the input image
INFO - class com.krozona.databaseaccess.service.DbService: Couldn't find a match for the input image


 <---- for third request ----->
 INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Number of elements in incomingImage byte array: 64528
 INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Number of elements in incomingImage byte array: 64528
 INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Number of elements in incomingImage byte array: 64528
 INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Magazine Name is: Maxim
 INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Magazine Name is: Maxim
 INFO - class com.krozona.databaseaccess.gatewayService.GetTagsAction: Magazine Name is: Maxim
 INFO - class com.krozona.databaseaccess.service.DbService: Couldn't find a match for the input image
 INFO - class com.krozona.databaseaccess.service.DbService: Couldn't find a match for the input image
 INFO - class com.krozona.databaseaccess.service.DbService: Couldn't find a match for the input image

这是 struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd" >
<struts>
    <constant name="struts.devMode" value="true" />
    <package name="Krozona" namespace="/" extends="struts-default" >

    <action name="GetTags" class="com.krozona.databaseaccess.gatewayService.GetTagsAction" method="execute">
        <result name="success" type="stream">
            <param name="contentType">text/plain</param>
            <param name="inputName">inputStream</param>
        </result>
        <result name="failure">/HelloWorld.jsp</result>
  </action>

  </package>
</struts>

为什么这种奇怪的行为?以及如何解决这个问题?

0 个答案:

没有答案