response.sendRedirect("pleaselogin.jsp?errorMessage=1");
这样就可以了,传的参数接在后面。

解决方案 »

  1.   

    我想让他以post的方式传递,不要以get的方式出现在url里.
      

  2.   

    不要用URL(绝对路径),http://localhost:8080/site/index.jsp。用URI(相对路径):request.getRequestDispatcher("/site/index.jsp").forward(request,response);
      

  3.   

    用重定向的是个http的绝对路径呢?
      

  4.   

    如果都是在同一个web server中的话,还是用URI,如果不是,就用URL和URLConnection类来做。1.你在site1中的servlet想转发到site2中的jsp:request.getRequestDispatcher("/site2/index.jsp").forward(request,response);
      

  5.   

    用URL和URLConnection类,应该如何写?
      

  6.   

    你狠......URLWrapper.java
    ----------
    import java.io.*;
    import java.net.*;public class URLWrapper
    {

    /**
     * 发送http网络请求.<br>用编程方式发送一个http网络请求到目的链接, 如果发送成功返回服务器响应字符串
     *
     * @param href 链接
     * @param method 方法
     * @param params 参数
     * @return 服务器响应返回的字符串
     * @throws 所有异常
     */
    public static String sendHttpRequest(String href, String method, String params) throws Exception
    {
    //System.out.println("URLWrapper.sendHttpRequest begin");
    // 创建http连接
    URL url = new URL(href);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    // 设定发送方法
    conn.setRequestMethod(method);

    // 写入参数
    conn.setDoOutput(true);
    PrintWriter out = new PrintWriter(conn.getOutputStream());
    out.println(params);
    out.close();

    // 获得服务器返回字符串
    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    StringBuffer sb = new StringBuffer();
    String line = "";

    while ((line = in.readLine()) != null)
    {
    sb.append(line + System.getProperty("line.separator"));
    }

    in.close();

    //System.out.println("URLWrapper.sendHttpRequest end");
    return sb.toString();
    }
    }
    ----------
    in servlet or jsp
    ----------
    import java.util.*;String url = "http://localhost:8080/site/index.jsp";String method = "POST";String params = "";// 注意,没试过如果有同名属性的状况
    Map map = request.getParameterMap();
    for ( Iterator it = map.keySet().iterator(); it.hasNext(); ) 
    {
        String name = it.next().toString();
        
        params += "&" + name + "=" + map.get(name).toString();
    }out.println(URLWrapper.sendHttpRequest(url, method, params));----------