Servlet和jsp中跨應(yīng)用的Session怎么???

跨應(yīng)用的Session
注意跨應(yīng)用的Session是取不出來的。我的應(yīng)用是ServletHello,第二個應(yīng)用名字叫CookieTest,你可以觀察到 QueryCookie這個Servlet已經(jīng)運行了,但就是Session取不出來??梢钥紤]用文件、數(shù)據(jù)庫,URL傳值、隱藏表單傳遞session id等。初學者不必關(guān)心。
馬克- to-win:馬克 java社區(qū):防盜版實名手機尾號: 73203。
package com;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
public class ServletHello2 extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession hs=request.getSession();
        hs.setAttribute("isLogin", "true");
        response.sendRedirect("http://localhost:8080/CookieTest/QueryCookie");
    }
}



package com;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class QueryCookie extends HttpServlet {
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        HttpSession hs=request.getSession();
        System.out.println("isLogin in Cookie Test Project is "+ hs.getAttribute("isLogin"));
    }
}

輸出結(jié)果是:

isLogin in Cookie Test Project is null





作業(yè):

0)編一個servlet,顯示客戶端的IP地址。(String ip=request.getRemoteAdddr();)
1.5)在Servlet1中存入Session變量LoginName="Mary",在Servlet2中打印LoginName.
1,8)把我index.html提交到一個servlet,打印表單中Username和Password. If Username is "zhangsan" and Password is "123", output "correct", otherwise output "wrong password".
2)把我index.html提交到一個servlet, 再在另一個servlet中顯現(xiàn)出來。
3) 編一個servlet,記錄servlet一共被訪問多少次自從啟動后。
4)編一個servlet,記錄servlet一共被某個人訪問多少次自從啟動后。  

課外作業(yè):
編一個servlet,記錄servlet一共被訪問多少次無論多少次啟動。(用文件)