RE:problemas con el request
Tu problema es sencillo de resolver:
Lo que te recomiendo que utilices es HttpClient es un proyecto que pertenece a Commons de Jakarta donde mas verdad???
http://jakarta.apache.org/commons/httpclient/
Lo voy a explicar con un servlet este servlet recibe un parametro que se llama nombre y lo imprime en la consola
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Boston, MA 02111.
* */
package org.neos.http.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class for Servlet: HelloWorld
*
*/
public class HelloWorld extends javax.servlet.http.HttpServlet
implements javax.servlet.Servlet {
public HelloWorld() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String nombre= request.getParameter("nombre");
System.out.println(nombre);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
Ahora desde un main mando a ejecutar el servlet pasandole los parametros necesarios en este caso nombre
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Boston, MA 02111.
* */
package org.neos.http.client;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
public class TestHttp {
static final String LOGON_SITE = "localhost";
static final int LOGON_PORT = 8080;
public static void main(String args[]) throws HttpException, IOException {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
//localizacion del servlet
PostMethod authpost = new PostMethod("/WebProject/HelloWorld");
// Prepare login parameters
NameValuePair action = new NameValuePair("nombre", "Mario");
authpost.setRequestBody(
new NameValuePair[] {action});
client.executeMethod(authpost);
System.out.println("Login form post: " + authpost.getStatusLine().toString());
// release any connection resources used by the method
authpost.releaseConnection();
}
}
checa la salida del tomcat y efectivamente llega la peticion completa....
los jars que necesitas cson:
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-httpclient-3.0.1.jar
commons-logging-1.0.3.jar
Espero que te sirva el codigo fuente
No olvides visitar nuestro Sitio ;-)
http://www.geocities.com/neos_software/
Mario Hidalgo, Web Master de Neos Software Inc.
Saludos comunidad Open Source