我简单说一下我要实现的目的,在客户端我要用一个httpclient向服务端的一个servlet发送请求(随便一个字符串abc)。此请求信息为get方法。服务端的servlet接受到客户端的请求后,将接受到的内容后面加上另一字符串(随便123)返回。我的服务端用了一个tomcat6.0.30版本的,是个zip压缩包,解压缩后,在eclipse中又创建一个server,把服务端(web工程)加进去。我如下测试tomcat:启动tomcat,本机可以访问自己在web工程的webcontent的一个jsp页面。现在,我想知道,我怎么配置才能去用我的客户端去访问到这个servlet,就是访问这个单纯的servlet,servlet里实现对请求信息的处理,之后返回给客户端。是不是要在servers(就是创建的那个server)下面配置一些server.xml 或者web.xml之类的。
小弟是新手,若有哪位好心前辈指点迷津,小弟感激不尽!!若想了解更我更多的配置或者什么,加我qq:786230163,24小时在线!!
求前辈指点迷津!!!!

解决方案 »

  1.   

    你可以百度一下 “servlet 配置” ;
    就是在web.xml里做个映射
      

  2.   


    /**
        * @param url like http://www.test.com/xx.do.
        * @param params GET method pass parameters.
        * @param props Http request properties.
        * @param proxy proxy.
        * @return
        */
       private HttpURLConnection connection(String url,
             Map<String, String> params, Map<String, String> props, Proxy proxy)
          HttpURLConnection conn = null;
          StringBuffer urlParams = new StringBuffer();
          Iterator<Entry<String, String>> it = params.entrySet().iterator();      while(it.hasNext()) {
             if(urlParams.length() > 0) {
                urlParams.append("&");
             }         Entry<String, String> entry = it.next();
             urlParams.append(entry.getKey());
             urlParams.append("=");
             urlParams.append(URLEncoder.encode(entry.getValue(), charset));
          }     url = url + urlParams;      if(proxy == null) {
             conn = (HttpURLConnection) new URL(url).openConnection();
          }
          else {
             conn = (HttpURLConnection) new URL(url).openConnection(proxy);
          }      conn.setRequestMethod(requestMethod);
          conn.setDoInput(doinput);
          conn.setDoOutput(dooutput);
          conn.setConnectTimeout(connectTimeout);
          conn.setReadTimeout(readTimeout);
          conn.setAllowUserInteraction(allowuserinteraction);
          conn.setInstanceFollowRedirects(followRedirects);
          conn.setUseCaches(usecaches);
          conn.setRequestProperty("Content-Type", "text/html; charset=" + charset);      if(props != null && !props.isEmpty()) {
             Iterator<Entry<String, String>> itp = props.entrySet().iterator();         while(itp.hasNext()) {
                Entry<String, String> entry = itp.next();
                conn.setRequestProperty(entry.getKey(), entry.getValue());
             }
          }     return conn;
       }
      

  3.   

    我仔细读过你的条件了,你架tomcat的方法跟我相同,都是创建一个server,server自动的将tomcat的一些配置文件,比如说web.xml和server.xml等等都给复制了过来,不同的是,在server.xml中,将站点设置为了你的web工程而已。
    楼上的大哥们其实已将告诉你了,若要访问servlet,需要在web.xml中添加几个映射即可。
    但是,你要在你的web工程下面的web-inf下面的web.xml中配置,否则提示找不到你所指定的类。
    另外,你请求HttpGet的时候,url一定要写清楚,想好你所编写的工程的环境,是应该用localhost 还是用你的ip地址。尤其是你用虚拟机的时候。