jsp转静态例子
1个Servlet:SetCharacterEncodingFilter.java
package com.util;
import java.io.IOException;
import javax.servlet.*;
public class SetCharacterEncodingFilter implements Filter{
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destroy()
{
this.encoding = null;
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException
{
if (ignore || (request.getCharacterEncoding() == null))
{
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException
{
this.filterConfig = filterConfig;
// 获取初始化参数
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
{
this.ignore = true;
} else if (value.equalsIgnoreCase("true"))
{
this.ignore = true;
} else if (value.equalsIgnoreCase("yes"))
{
this.ignore = true;
} else
this.ignore = false;
}
protected String selectEncoding(ServletRequest request)
{
return (this.encoding);
}
}
一个过滤器 JspFilter.java:
package com.util;
import java.io.IOException;
import jav
相关文档:
JSP中的COOKIE操作
Cookie概念:
Cookie的格式实际上是一段纯文本信息, 由服务器随着网页一起发送到客户端, 并保存在客户端硬盘中指定的目录的. 大家都传说Cookie会造成严重的安全威胁什么的, 其实不是这么回事情. 服务器读取Cookie的时候, 只能够读取到这个服务 ......
Servlet:
在Servlet中,跳转在doGet或者doPost方法中实现。
<1>redirect实现页面跳转:
response.sendRedirect("/login.jsp");
方法的参数是相对路径,设定这个参数可以使页面跳转到任何页面,包括www.baidu.com等网络页面。
跳转后你可以发现地址栏发生了变化。
底层原理:使用redir ......
·pageContext:提供对页面属性的访问。
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("basePath",basePath);
%>
使用:
${pageScope}
·reques ......
session就是一个全局变量,是浏览器线程在服务器端的代理。web服务程序只要打开,session就会存在,当你第一次访问时,session会自动为你分配一个session ID,所以session为新建立的,所以session.isNew()为true。当你刷新页面时,这个session ID一直存在(session.getId()不变),不会消失,所以se ......