To run it “pseudo” locally (for example, on the command line), you must first deploy it and then use HttpClient to connect to your server. This way you can interact with your / jsp servlet from the command line and not send forms with attachments
Sample code [You can, of course, get more creative than this]
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.client.ClientProtocolException; public class FileUploaderClient { public static void main(String[] args) throws ClientProtocolException, IOException{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://<app-version>.<app-name>.appspot.com/<servlet-name>"); MultipartEntity reqEntity = new MultipartEntity(); FileBody bin = new FileBody(new File("<File you want to upload>")); reqEntity.addPart("file", bin); httppost.setEntity(reqEntity); HttpResponse response = httpclient.execute(httppost); System.out.println(response.getStatusLine()); } }
Now you will have the opportunity to call your servlet in a loop, for example, instead of submitting the form several times
source share