比如你的工程名c:\app1
在server.xml中加入一个新的context.
<context></context>
在IE中http://localhost/app1/servlet/hehe也可以使用URI编辑web.xml
这样就可以使用URI了。

解决方案 »

  1.   

    http://www.cn-java.com/index_focus.php?kind=15&title=Applet%D3%EBSwing
      

  2.   

    new URL(getCodeBase(),"/servlet/hehe");
      

  3.   

    我一直在摸索、:
    用了上面knight_qmh(辉) 和mengyou(变形金刚) 的方法:
    看它形成的url的字符串表示都对。是http://127.0.0.1:8080/servlet/hehe
    但是在java控制台里就显示成了:http://127.0.0.1:8080//servlet/hehe了
    请注意8080后面有两个"/".所以说找不到文件
    这是怎么回事!!服了
      

  4.   

    同意mengyou的方法,前提是包含该applet的页面和要调的servlet在同一个服务端
    不过你那种方法应该也能找到,我以前有一个applet就是那样写的:
    连接new URL("http://192.168.0.60:7001/MyWebApp/RolesReader"),控制台上打出来的URL也是http://192.168.0.60:7001//MyWebApp/RolesReader,但是调到了啊。
    你把URL直接输到IE地址栏看看能不能找到?还有你用的服务器是什么?
      

  5.   

    resin!!
    servlet文件就放到了web-inf/class下。
    并且用html的表单就可以找到hehe.奇怪!
      

  6.   

    错误代码如下:
    url的toString()为:http://127.0.0.1:8080/servlet/hehe在控制台里就显示如下:java.io.FileNotFoundException: 127.0.0.1:8080//servlet/hehe
    at com/ms/net/wininet/http/HttpInputStream.connect
    at com/ms/net/wininet/http/HttpInputStream.<init>
    at com/ms/net/wininet/http/HttpURLConnection.createInputStream
    at com/ms/net/wininet/WininetURLConnection.getInputStream
    at untitled1/Applet1.getConn
    at untitled1/Applet1.button1_mouseClicked
    at untitled1/Applet1$1.mouseClicked
    at java/awt/Component.processMouseEvent
    at java/awt/Component.processEvent
    at java/awt/Button.processEvent
    at java/awt/Component.dispatchEventImpl
    at java/awt/Component.dispatchEvent
    at com/ms/awt/ZComponentPeer.processEvent
    at java/awt/Component.dispatchEventImpl
    at java/awt/Container.dispatchEventImpl
    at java/awt/Component.dispatchEvent
    at java/awt/EventDispatchThread.run
    java.io.FileNotFoundException: 127.0.0.1:8080//servlet/hehe
      

  7.   

    new URL(getCodeBase(),"servlet/hehe");
    getCodeBase()方法返回的字符串已经包含一个路径分隔符了!
    我刚刚做过一个applet->servlet-EJB的东东,没有什么技术上的问题啊。
      

  8.   

    以下是我写的一个方法,是JApplet的子类的方法:
        private void getObject() {
            urlString=new StringBuffer();
            String hosts=getDocumentBase().toString()+"servlet/Servlet_mrp14a08_Servlet?";
            urlString.append("key=codeview");
            try {
                URL url=new URL(hosts+urlString.toString());
                URLConnection uc = url.openConnection();
                uc.setDoOutput(true);
                uc.setUseCaches(false);
                ObjectInputStream objStream=new ObjectInputStream(uc.getInputStream());
                record=(mrp14a08_WkdbAllData)objStream.readObject();
                if (record==null) {
                    getAppletContext().showDocument(new URL(getDocumentBase().toString()+"com_FormSystemError.jsp"),"_top");
               }
            }
            catch (Exception e) {
                System.out.println (e);
            }    }
      

  9.   

    我试过了。URL url=new URL(getCodeBase()+"/servlet/hehe");
    和URL url=new URL(getCodeBase()+"servlet/hehe");的url.toString()
    显示的都一样。