关于jsp中的cookie小程序
<body>
<%
Cookie[] cookies = request.getCookies() ;
Cookie cookie = null ;
if(cookies!=null){
cookie = cookies[0] ;
out.print("上次访问的ip是: " + request.getRemoteAddr() +"<br>") ; //得到客户端的ip
out.print("上次访问时间:" + cookie.getValue()) ;
cookie.setValue(new java.util.Date().toString()) ;
response.addCookie(cookie) ; //保存到客户端
cookie.setMaxAge(365 * 24 * 3600);
}
if(cookies==null){
cookie = new Cookie("AccessTime","") ;
cookie.setValue(new java.util.Date().toString()) ;
response.addCookie(cookie) ; //保存到客户端
cookie.setMaxAge(365 * 24 * 3600);
}
%>
</body>
ps:如果没有设置cookie的有效期,那么在关闭浏览器时cookie会被删除。如果生命期为负整数,表示这个cookie对象是临时的,不要保存在硬盘中,关闭浏览器后数据会自动丢失!
相关文档:
(一)包含其他页面的方法:
include指令:<%@ include file = "test1.jsp" %>
静态包含,可以包含任意格式的文件(不光是jsp文件,还可以是txt等文本文件),静态包含就是将被包含文件的内容拷贝到包含文件中,进行执行。当前页面和test1.jsp中不能有重名的变量。
include动作 <jsp:include page = "tes ......
jsp中文显示乱码解决方案2006-12-27 22:56
一、JSP页面显示乱码
二、表单提交中文时出现乱码
三、数据库连接
大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着您,我现在把我在JSP开发中遇到
的中文乱码的问题及解决办法写出来供大家参考。
一、JSP页面显示乱码
下面的显示页面(display.jsp)就出现乱 ......
<html:html>
<HEAD>
<tiles:insert attribute="header" />
</HEAD>
<body>
<tiles:insert attribute="top" />
<table width="100%" height="400" border="0" align="center"
cellpadding="0" cellspacing="0">
<tr>
<td width="178" ......
<table width=100% border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td height="1" class="gray1"></td>
</tr>
</table>
<tiles:insert attribute="footer" />
</body>
</html:html> ......
<%@page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="ccp.suddenattack.service.news.*"%>
......