response.setCharacterEncoding("gb2312")与你的getXXX有关,
response.setContentType("text/html;charset=gb2312")与显示页面有关。我是这么理解,你可以看API呀。。
response.setContentType("text/html;charset=gb2312")与显示页面有关。我是这么理解,你可以看API呀。。
解决方案 »
- 请问一个SQL
- 请问这个网站上的pdf浏览器是用的flex开发的吗?
- 标签问题
- c# \java \javascript如何根据网址 获得 网站的标题
- 求助关于cvsnt的问题急啊!在线!
- 中间表 hibrenate反转问题!
- !!!!!急用。jsp中访问文件,我这里有段代码,但总显示file not found.是什么原因?哪位高手知道?
- 100分请教 Ultra Dev(JSP) + SQL server2000 + resin + win98 问题
- 关于在 servlet 中,service 以及 doGet、doPost应用的问题?!------------请进:)
- 关于java后台传给前台图片路径,前台访问不到的问题。
- 关于输出XML文件的中文编码问题,急!!!!!
- URI和URL的区别~~
那几个应该是改变显示数据或字的字体咯.
没有用过。
同意naxin(痴呆男人--我痴呆,我自豪!!) 的说法
只有request.setCharacterEncoding()这个方法!
response.setContentType("text/html;charset=gb2312")是设置页面中为中文编码
前者是设置动态文字(参数,数据库),后者设置页面静态文字
protected Log log = LogFactory.getLog(this.getClass().getName());
protected User oUser;
protected Response oResponse;
protected String params;
protected XmlParse oXml=null;
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{ response.setCharacterEncoding(HttpParams.getString(Constants.CHARCODE)); //$NON-NLS-1$
if(!isLogin(request, response)){
//return mapping.findForward("error.login.notlogin");
return null;
}
params = request.getParameter(HttpParams.getString(Constants.PARAMS)); //$NON-NLS-1$
if((params!=null)&&(!params.equalsIgnoreCase(""))){
if(!initParam()){
return null;
}
}
return _execute(mapping, form, request, response, params);
}我的代碼1直都正確
ServletResponse的源代码如下(来自:D:\borland\JBuilderX\extras\jakarta-servletapi-4-src.zip\jakarta-servletapi-4-src\src\share\javax\servlet,我删除了注释信息,):
package javax.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
public interface ServletResponse {
public String getCharacterEncoding();
public ServletOutputStream getOutputStream() throws IOException;
public PrintWriter getWriter() throws IOException;
public void setContentLength(int len);
public void setContentType(String type);
public void setBufferSize(int size);
public int getBufferSize();
public void flushBuffer() throws IOException;
public void resetBuffer();
public boolean isCommitted();
public void reset();
public void setLocale(Locale loc);
public Locale getLocale();
}
/**
* Sets the character encoding (MIME charset) of the response
* being sent to the client, for example, to UTF-8.
* If the character encoding has already been set by
* {@link #setContentType} or {@link #setLocale},
* this method overrides it.
* Calling {@link #setContentType} with the <code>String</code>
* of <code>text/html</code> and calling
* this method with the <code>String</code> of <code>UTF-8</code>
* is equivalent with calling
* <code>setContentType</code> with the <code>String</code> of
* <code>text/html; charset=UTF-8</code>.
* <p>This method can be called repeatedly to change the character
* encoding.
* This method has no effect if it is called after
* <code>getWriter</code> has been
* called or after the response has been committed.
* <p>Containers must communicate the character encoding used for
* the servlet response's writer to the client if the protocol
* provides a way for doing so. In the case of HTTP, the character
* encoding is communicated as part of the <code>Content-Type</code>
* header for text media types. Note that the character encoding
* cannot be communicated via HTTP headers if the servlet does not
* specify a content type; however, it is still used to encode text
* written via the servlet response's writer.
*
* @param charset a String specifying only the character set
* defined by IANA Character Sets
* (http://www.iana.org/assignments/character-sets)
*
* @see #setContentType
* #setLocale
*
* @since 2.4
*
*/ public void setCharacterEncoding(String charset);
response.setCharacterEncoding设置HTTP 响应的编码,如果之前使用response.setContentType设置了编码格式,则使用response.setCharacterEncoding指定的编码格式覆盖之前的设置.与response.setContentType相同的是,调用此方法,必须在getWriter执行之前或者response被提交之前.
我正在看无废话xml,也要学习各位大虾的指点.
谢谢.