标题:请大神帮我解决一个问题
只看楼主
北京流浪者
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2013-12-18
结帖率:0
 问题点数:0 回复次数:0 
请大神帮我解决一个问题
import
import
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class H extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            Thread thread=new MyThread(request);
            thread.start();
    }

}
class MyThread extends Thread{
    HttpServletRequest httpServletRequest=null;
    public MyThread(HttpServletRequest httpServletRequest){
        this.httpServletRequest=httpServletRequest;
        System.out.println("构造方法中"+httpServletRequest.getSession());
    }
     @Override
    public void run() {
        while(true){
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("我是线程------"+this.getName());
            System.out.println("run方法中"+httpServletRequest.getSession());
        }
    }
}

jsp方面:--------------------------
<script type="text/javascript">
         $(function(){
             $("#b1").click(function(){
                 $.get("H",{},function(message,stutes){
                 alert(message+"--------------------");


              });   
             });


           });
         
    </script>
 <input type="button" id="b1" value="Click me" />
/*为什么上面输出httpServletRequest.getSession()的值是null,输出httpServletRequest的值就不是null呢?*/
搜索更多相关主题的帖子: request thread public import 
2013-12-19 08:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-425388-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.216558 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved