如何检测浏览器的脚本和Cookies功能是否打开?
本文导语: | Browser Capabilities Component可以检测浏览器的这些功能 它支持17种属性,其中 Cookies:检测cookies功能 Vbscript: Javascript: Jscript: JavaApplets: 这些功能不用多说了吧 | 自己编译运行这个servlet看看吧。 import...
|
它支持17种属性,其中
Cookies:检测cookies功能
Vbscript:
Javascript:
Jscript:
JavaApplets:
这些功能不用多说了吧
|
import java.io.*;
import java.util.Enumeration;
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionDemo extends HttpServlet {
public String getServletInfo() {
return "SessionDemo version 1.9: a sample servlet from vqSoft";}
public void dostuff (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
HttpSession tsession=req.getSession(true);
res.setContentType("text/html");
ByteArrayOutputStream buffer=new ByteArrayOutputStream();
PrintWriter os=new PrintWriter(buffer);
//PrintWriter os=new PrintWriter(res.getOutputStream());
Integer sessioncounter=(Integer) tsession.getValue("sessioncounter");
if (sessioncounter==null)
sessioncounter=new Integer(1);
else
sessioncounter=new Integer(sessioncounter.intValue()+1);
tsession.putValue("sessioncounter", sessioncounter);
if (req.getParameter("submitdata")!=null) {
tsession.putValue(req.getParameter("name"), req.getParameter("value"));}
os.println("Session demonstration");
os.println("");
os.println("");
os.println("");
os.println("Session demonstration");
os.println("");
os.println("
This page was generated by SessionDemo version 1.9, a sample servlet supplied with vqServer. ");
os.println("SessionDemo illustrates vqServer's support for JavaSoft sessions. ");
os.println("During a session, the server can keep track of data between HTTP requests.
os.println("
");
os.println("Access this servlet and session using URL encoding.
");
os.println("");
os.println("Request parameters");
os.println("Requested session ID: "+req.getRequestedSessionId()+"
");
os.println("Session ID from cookie: "+req.isRequestedSessionIdFromCookie()+"
");
os.println("Session ID from URL: "+req.isRequestedSessionIdFromUrl()+"
");
os.println("Valid session requested: "+req.isRequestedSessionIdValid()+"
");
os.println("");
os.println("Session parameters");
os.println("Actual session ID: "+tsession.getId()+"
");
os.println("Creation time: "+(new Date(tsession.getCreationTime())).toString()+"
");
os.println("Last access time: "+(new Date(tsession.getLastAccessedTime())).toString()+"
");
os.println("New session: "+tsession.isNew()+"
");
os.println("");
os.println("Session data");
os.println("Counter: "+sessioncounter.toString());
String[] tdata=tsession.getValueNames();
for (int i=0; i