解决方案 »
- The requested resource () is not available.
- tomcat6.0如何配置数据库连接池
- 关于DWR中调用DAO插入方法的问题
- 关于java解析txt文档,再将txt文档数据导入sql server 中的问题请教
- 分页问题
- 如何对hibernate返回的list处理后再返回呢?
- 关于论坛贴图的问题!!
- oracle中rs.getString("number字段")后返回值如何格式化保留两位小数点的问题?
- 请问在resin下执行为什么javaBean出错?
- 请问用代码怎样来实现 树型目录的输出,数据从数据库里面取出来?
- 为什么获取不到对象
- form表单如何获取数组参数呢?
response.setCharEncoding("GBK");
--
将上面的代码写在servlet 请求的方法上的第一行
--
或者用过滤器
--
下面是过滤器类 类名自定义
package filter;import java.io.*;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); }
}
--
WebRoot/WEB-INF/
web.xml
--
<?xml version="1.0" encoding="UTF-8" ?>
- <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
- <filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filter.SetCharacterEncodingFilter</filter-class>
- <init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
- <filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<jsp:getProperty name="login" property="logname"/>
没有<jsp:setProperty name="login"/>,get是拿不到值的,
<jsp:useBean id="login" type="natures.bean.Login" scope="session"/> 这句话等于重新创建了个对象,没给值,就像拿值,肯定是null
额,这一大堆。。
没搞清楚您指的是放哪里..囧...经我窒息一段时间,今晚又费了几个小时,终于发现问题了,悲剧....是字符集的问题。有一个页面的页面属性 Charset=GB2312写成了chareset=GB2312然后,在servlet中的字符串也要用以下方法修改下:(JAVA中默认的字符集是UTF-8,而我的页面为GBK2312) String s="游客 " ;
byte bb[]=s.getBytes("GBK2312");
s=new String(bb);
loginbean.setLogname(s);终于解决了好悲剧