对于乱码的处理--通过filter解决乱码问题
方法:在对网页的请求到达之前,先经过Filter的处理,即新建一个filter
操作流程:右击项目 --> new --> Filter -->下图
点击next,修改filter mappings为/*,勾上4个选项,然后ok,
点击finish,完成新建,在doFilter方法中添加2行,详细代码如下
package myFilter;
import java.io.IOException;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
/**
* Servlet Filter implementation class EnCodingFilter
*/
@WebFilter(dispatcherTypes = {
DispatcherType.REQUEST,
DispatcherType.FORWARD,
DispatcherType.INCLUDE,
DispatcherType.ERROR
}
, urlPatterns = { "/*" })
public class EnCodingFilter implements Filter {
/**
* Default constructor.
*/
public EnCodingFilter() {
// TODO Auto-generated constructor stub
}
/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
// pass the request along the filter chain
chain.doFilter(request, response);
}
/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}
}
struts 1.x 标签的学习
struts 1.x的标签用的不多,仅需要记住常见几种标签的作用,需要用到的时候查一下就ok
bean:用来创建bean、访问bean和访问bean的属性
html:用来创建Struts的输入表单
logic:用来进行逻辑判断、集合迭代和流程控制。
nested:建立在前三个标签库的基础上,具有前三个标签库的所有功能,只是允许标签间的嵌套
tiles:用来创建tiles样式的页面/
循环遍历标签<logic:iterate>