Tomcat迁移至Websphere遇到的问题

应用框架如下:Struts1.2Spring2.0Hibernate3.2

JDK的差别

不得不说Java的思想造福了大众,但是过多的Jdk版本我们不知所从,IBMJDKSUN官方的JDK有一些区别,我不知道区别有多大,但是我确实碰见了,如下代码:

       /**

        * 注意这个方法在IBM JDK下有错误

        *

        * @param passPhrase

        */

       public DesEncrypter(String passPhrase) {

              try {

                     // Crate the key

                     KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt,

                                   iterationCount);

                     SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(

                                   keySpec);

                     ecipher = Cipher.getInstance(key.getAlgorithm());

                     dcipher = Cipher.getInstance(key.getAlgorithm());

 

                     // Prepare the parameter to the ciphers

                     AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt,

                                   iterationCount);

 

                     // Create the ciphers

                     ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);

                     dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);

              } catch (Exception ex) {

                     ex.printStackTrace();

              }

       }

IBM JDKPBEWithMD5AndDES没有这个参数(注意红色字体部分),报错,无法实例化!如果使用了DES的加密,自己另想办法吧!IBM JDKJavaDoc,找了好久没有找到!

过于严苛的DTD问题

一个很简单的Spring配置文件,Tomcat下没有任何问题,WebSphere下在加载这个文件的时候会提示找不到beans定义错误,为什么呢?

xml version="1.0" encoding="UTF-8"?>

DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

    "http://www.springframework.org/dtd/spring-beans.dtd">

 

<beans>

……

改成以下形式吧,不要问为什么!

xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

……

FilterServlet加载顺序

Tomcat下工作久了,你会认为这不是个问题,但是Websphere下确实很灵异,过滤器会晚于Servlet加载,也就是说TomcatWebsphere处理这个问题的时候是相反的,Tomcat会先加载Filter,然后在加载你的Servlet,而Websphere,先处理Servlet,然后在处理Filter。以下代码中红色部分是在Filter中初始化的,在Websphere下,会取得null,而Tomcat很正常。

       /**

        * Initialization of the servlet.

        *

        * @throws ServletException

        *             if an error occure

        */

       public void init() throws ServletException {

              try {

                     ApplicationContext context = Context.getContext(this

                                   .getServletContext());

                     ISingleGenericDAO tempDao = (ISingleGenericDAO) context

                                   .getBean("singleGenericHibernateDAO");

                     List args = new ArrayList();

       args.add((String)this.getServletContext().getAttribute(GlobalNames.APP_PKXNXQ));

                     List list = tempDao.find("from Jx0408 where xnxqh = ?", args);

                     this.getServletContext().setAttribute(GlobalNames.APP_XKKB, list);

              } catch (Exception e) {

                     e.printStackTrace();

              }

       }

你可能感兴趣的:(JAVA,websphere,tomcat,servlet,jdk,exception,ibm)