在servlet的doPost里有
String taskdate = request.getParameter("date");
String round = request.getParameter("round");在另一个class里要得到taskdate和round的值,应该如何写呢?我试过用继承,好象不行

解决方案 »

  1.   

    通过session,application,文件,数据库传递
      

  2.   

    放到一个session中去,然后getsession就好了
      

  3.   

    session.setAttribute("taskdate",taskdate);
    设置进sessionsession.getAttribute("taskdate" );获取出来
      

  4.   

    我在servlet里加了
    ServletContext application = getServletContext(); 
    application.setAttribute("name",name);在另个类里写了String na = application.getAttribute(name);报错
    TaskEntry.java:29: cannot find symbol
    symbol  : variable application
      

  5.   

    需求是用application写
    在另外一个类里能用application.getAttribute(name);吗?
      

  6.   

    至少应该这样吧String na = application.getAttribute("name");
      

  7.   

    改成application.getAttribute("name");
    但还是报同样的错误
      

  8.   

    那没法调用application,这里application是容器上下文概念用传参数的形式或是通过文本文件数据库传递
      

  9.   

    对楼上正解,一个普通的类与application是无法联系的
      

  10.   

    如果两个都是servlet呢?我把代码修改了下servletA
    ServletContext application = getServletContext(); 
    application.setAttribute("name",name);servletB
    String name = application.getAttribute("name");还是取不到值,还需要加些什么吗?
      

  11.   

    两个servlet都要在容器里运行才行
      

  12.   

    都在容器里的意思是不是在web.xml里配置过?
      

  13.   

    我想在几个servlet间可以共同使用一个前台jsp请求传来的值我在servlet里想使用
    ServletContext application = getServletContext();
    的方法实现
    编译都能通过,但到jsp里请求提交时就在上面这句报错了
    description: The server encountered an internal error () that prevented it from fulfilling this request.
      

  14.   

    你不会是用ServletB serv = new ServletB();这种方式调用的B吧
      

  15.   

    不是的 我这么写的
    servletA里
    ServletContext application = getServletContext(); 
    application.setAttribute("name",name);
    servletB里
    String name = (String)application.getAttribute("name");我想请教下ServletContext在doPost里使用有什么要求吗?我在单个servlet里使用也有问题比如我想在servlet加个访问计数器
    ServletContext context = getServletContext();
    Integer id=(Integer)context.getAttribute("id");
    if(id==null)
    {
    d = new Integer(1);
    }
    else
    {
    id = new Integer(id.intValue()+1);
    }
    context.setAttribute("id",id);编译能通过,但到jsp里请求提交时就报错了
    description: The server encountered an internal error () that prevented it from fulfilling this request.
      

  16.   

    doPost请求是在有post的表单提交时才触发的,一般通过地址访问的用doGet
      

  17.   

    有post表单提交的
    在没有加ServletContext时运行正常,加了之后提交请求就报错了
      

  18.   

    B里有这一句么?
    ServletContext application = getServletContext();
      

  19.   

    实例化那个类,传递参数过去就行了。
    搞什么session传参数,要传也用request传,笨