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
相关文档:
我先说明一下配置环境的大概情况:
* FreeBSD 7.0-RELEASE
* apache-2.2.9
* mod_jk-ap2-1.2.26
* diablo-jdk-1.6.0.07.02
* tomcat-6.0.16
具体的版本信息显示如下:
freebsd# pkg_info
apache-2.2.9_5 Version 2.2.x of Apache web server&nbs ......
Servlet:
在Servlet中,跳转在doGet或者doPost方法中实现。
<1>redirect实现页面跳转:
response.sendRedirect("/login.jsp");
方法的参数是相对路径,设定这个参数可以使页面跳转到任何页面,包括www.baidu.com等网络页面。
跳转后你可以发现地址栏发生了变化。
底层原理:使用redir ......
在项目中,我们经常遇到需要在jsp页面切换中传递中文字符。这主要有两种方式。
URL方式,例如:http://website/test1.jsp?act=add&type=苹果¶m=%20D%20B
FORM方式,例如:
<form name=test mehtod="post">
<input type=hidden name=text2 value="中文">
<input type=t ......
修改了css 样式文件后,重新浏览该jsp页面,发现新修改的样式没有生效。总以为是项目缓存所引起的,于是清理所有项目,重新构建项目。不行。执行server 的 publish 还是不行。用window 的搜索功能发现除了 WebContent 目录有该 css 文件外,.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\ 目录下也存在该 c ......