可以直接在jsp得form 标签的action属性中用 当然要在web.xml中指定

解决方案 »

  1.   

    为什么要引用Servlet中的函数呢?自己建立一个Class不就OK了,Servlet是有容器来初始化的。
      

  2.   

    导入包就可以!
    如果servlet里面有相应的初始化参数,
    jsp也要相应的传过去
      

  3.   

    flyycyu(fly) 你所得挺有道理,但是一个问题你要明白,那就是我们要在jsp文件中调用Servlet产生的对象,有没有可能性?
      

  4.   

    你先要弄明白你是怎么调用!对于Servlet,我觉得你好象把
    调用Servlet和Servlet的http请求响应
    弄混了如果是Servlet的输出,当然不可能得到其对象,
    但是直接调用就是类似一个普通的java类,想想吧,Servlet容器怎样对Servlet进行调用的!
      

  5.   

    Servlet2.java:
    调用Servlet1.java中的Dopackage stest;import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;public class Servlet2 extends HttpServlet {
      static final private String CONTENT_TYPE = "text/html; charset=GBK";
      //Initialize global variables
      public void init() throws ServletException {
      }
      //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>Servlet2</title></head>");
        out.println("<body>");
        Servlet1 s = new Servlet1();
        out.println(s.Do());
        out.println("<p>The servlet has received a GET. This is the reply.</p>");
        out.println("</body></html>");
      }
      //Clean up resources
      public void destroy() {
      }
    }Servlet1.java:package stest;import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;public class Servlet1 extends HttpServlet {
      static final private String CONTENT_TYPE = "text/html; charset=GBK";
      //Initialize global variables
      public void init() throws ServletException {
      }
      //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>Servlet1</title></head>");
        out.println("<body>");
        out.println("<p>The servlet has received a GET. This is the reply.</p>");
        out.println("</body></html>");
      }
      public int Do()
      {
        return 2;
      }
      //Clean up resources
      public void destroy() {
      }
    }