初次配置使用weblogic

初次使用weblogic

weblogic下载地址

http://www.oracle.com/technology/software/products/ias/htdocs/wls_main.html

一、weblogic9注意下面问题:
问题一:pageEncoding不能重复定义
所以taglibs.jsp的头上只能这么写
<%@ page language="java" contentType="text/html; charset=GBK" %>

二、weblogic10.3注意下面问题:

问题一(标签问题):

<%@ taglib prefix="sccl" tagdir="/WEB-INF/tags"%>(正确写法)
<%@ taglib prefix="sccl" tagdir="/WEB-INF/tags/"%>(错误写法)
发布时在TOMCAT6上好好的,应为最后那个/WEB-INF/tags/后面多了一个/,导致启动的时候报找不到tag file。去掉后面的/后就好了。

问题二(weblogic中文支持问题):

JSP文件之间不能正确传递中文数据。可以检查下以下配置:
1、在WEB-INF/web.xml里加上如下脚本(这个从weblogic的日志看,在10.3中已经被废弃了):
<context-param>
<param-name>weblogic.httpd.inputCharset./*</param-name>
<param-value>GBK</param-value>
</context-param>
2、在WEB-INF/weblogic.xml里加上如下脚本:
<charset-params>
<input-charset>
<resource-path>/*</resource-path>
<java-charset-name>GBK</java-charset-name>
</input-charset>
</charset-params>
确保在POST和GET时候都是用GBK,还要确保WebLogic应用服务器所在操作系统的字符集,确保支持中文
3、在META-INF/weblogic-application.xml加入上如下脚本:
<wls:application-param>
    <wls:param-name>webapp.encoding.default</wls:param-name>
    <wls:param-value>GBK</wls:param-value>
</wls:application-param>
4、在BEA_HOME目录的启动参数中增加如下参数
我的路径是
D:\tool\bea\user_projects\domains\kiko9\bin\setDomainEnv.cmd
set JAVA_OPTS="-Ddefault.client.encoding=GBK -Dfile.encoding=GBK -Duser.language=zh - Duser.region=CN"

以上办法都测试了,结果发现不是URLENCODING这里的问题,因为我URL跟了中文的参数,可以正常显示中文
URL测试JSP页面:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common/head.jsp"%>
<%@ include file="/common/headExt.jsp"%>
<a href="${ctx}/test/mytag.jsp?s=中文">Test GBK requestUrl</a>
<h1>${param.s}</h1>

却是在ext的ajax post的时候才出乱码,所以我用http watch跟踪了一下,POST上去的数据是中文的,首先进入了我们的
CharactorEncodingFilter代码,发现了是ajax的POST请求,会设置为utf-8的编码,但是奇怪的是,到了controller里面后,这个设置却没有生效,跟踪日志显示
DevLog.trace(request.getCharacterEncoding());
打印出的是GBK,并显示了乱码。
我在CharactorEncodingFilter设置了断点,这次
DevLog.trace(request.getCharacterEncoding());
又奇迹般的得到了UTF-8,并显示了中文。

难道又是以前遇到过的那个要重复设置第二次的问题,我将CharactorEncodingFilter.java修改如下后,系统乱码问题解决:
package cn.sccl.cpmis.common.web;
import java.io.IOException;
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.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CharactorEncodingFilter implements Filter {
private final static String DEFAULT_ENCODING = "GBK";
private final static String ajaxEncoding = "UTF-8";
protected String commonEncoding;
protected FilterConfig filterConfig;
protected boolean ignore = true;
public CharactorEncodingFilter() {
   super();
}
public void init(FilterConfig filterConfig) throws ServletException {
   this.filterConfig = filterConfig;
   this.commonEncoding = filterConfig.getInitParameter("encoding");
   if (this.commonEncoding == null) {
    this.commonEncoding = DEFAULT_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;
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) {
   try {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    // 接受第三方cookie
    //response.addHeader("P3P","CP=CAO PSA OUR");
    //response.setHeader("P3P", "CP=CAO PSA OUR");
    if (ignore || (request.getCharacterEncoding() == null)) {//ajax post with the header named RequestType
     if (request.getHeader("RequestType") != null
       && request.getHeader("RequestType").equalsIgnoreCase("ajax")) {
      request.setCharacterEncoding(ajaxEncoding);
      response.setCharacterEncoding(ajaxEncoding);
if(!ajaxEncoding.equalsIgnoreCase(request.getCharacterEncoding())){
//此处代码无法理解。哈哈。不这么写,weblogic10.3就是在ajax提交的时候有乱码
request.setCharacterEncoding(ajaxEncoding);
response.setCharacterEncoding(ajaxEncoding);
}
      response.setContentType("text/html;charset=" + ajaxEncoding);
     } else if (request.getHeader("X-Requested-With") != null
       && request.getHeader("X-Requested-With").equalsIgnoreCase("XMLHttpRequest")) {
      request.setCharacterEncoding(ajaxEncoding);
      //WARNING, the under line not allowed
      //response.setCharacterEncoding(ajaxEncoding);
      response.setContentType("text/html;charset=" + commonEncoding);
     } else {
      request.setCharacterEncoding(commonEncoding);
      response.setCharacterEncoding(commonEncoding);
      response.setContentType("text/html;charset=" + commonEncoding);
     }
    }
    filterChain.doFilter(req, res);
   } catch (IOException e) {
    e.printStackTrace();
   } catch (ServletException e) {
    e.printStackTrace();
   }
}
public void destroy() {
   this.commonEncoding = null;
   this.filterConfig = null;
}
}
其中黑体字就是增加的代码。呵呵。反正是和上次一样解决了问题。但是原因和以前一样,不理解。
另外贴出weblogic.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<context-root>/cpmis</context-root>
<charset-params>
   <input-charset>
    <resource-path>/*</resource-path>
    <java-charset-name>GBK</java-charset-name>
   </input-charset>
</charset-params>
<container-descriptor>
   <prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
完整weblogic-application.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-application" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-application http://www.bea.com/ns/weblogic/weblogic-application.xsd http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd">
<wls:application-param>
    <wls:param-name>webapp.encoding.default</wls:param-name>
    <wls:param-value>GBK</wls:param-value>
</wls:application-param>
</wls:weblogic-application>

你可能感兴趣的:(Ajax,jsp,Web,weblogic,servlet)