蒋德的JAVA备忘录

JAVA备忘录

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  14 随笔 :: 4 文章 :: 5 评论 :: 0 Trackbacks

2009年8月23日 #

weblogic10.3 这个应用服务器是oracle 收购Bean 公司后新出的版本.今天试用下,发现不错.将JNDI的配置过程一一记录,
1: 启动weblogic 10.3 采用默认密码进入
2:在JDBC-DATASOURCE 中假建一个应用数据源.
3:在 Configuration-->Connection Pool-->Advanced 中的  一定要沟上,不然会测试通不过
4:填写测试的表名    等信息

5:编写测试的JSP文件

<!doctype html public "-//w3c//dtd html 4.0 transitional//en"   "http://www.w3.org/TR/REC-html40/strict.dtd">
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%@ page session="false"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test JNDI</title>
</head>
<body>
    
<%
    out.print(
"  Test Jndi Begin !!    ");
    DataSource ds 
= null;
    
try {
        InitialContext ctx 
= new InitialContext();
        ds 
= (DataSource) ctx.lookup("jdbc/mysql");
        Connection conn 
= ds.getConnection();
        Statement stmt 
= conn.createStatement();
        String strSql 
= " select * from tb_adminuser";
        ResultSet rs 
= stmt.executeQuery(strSql);
        
while (rs.next()) {
            out.println(rs.getString(
4));
        }

        out.print(
"Test is over");
    }
catch (Exception ex) {
        out.print(
"ERROR:" + ex.getMessage());
        ex.printStackTrace();
    }

%>
</body>

</html>

6:编写 JUNIT
package com.XXXXXX.framework.datasource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import junit.framework.TestCase;

public class TestJndi extends  TestCase{

    
    
public void testJndi() throws Exception{
        Hashtable ht 
= new Hashtable();          
        ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
        ht.put(Context.PROVIDER_URL, 
"t3://localhost:7001");
        Context initial 
= new InitialContext(ht);
        DataSource ds 
= (DataSource) initial.lookup("jdbc/mysql");
        Connection connect 
= ds.getConnection();

        Statement stmt 
= connect.createStatement();   
        String strSql 
= " select * from tb_adminuser";   
       
        ResultSet rs 
= stmt.executeQuery(strSql);   
        
while(rs.next()){   
            System.out.println(rs.getString(
2));
          }
  

    }



}

其中在编写JUNIT 的时候,有一个插曲.我在网上看到别人的代码是用t3://localhost:7007

我也照COPY,结果出现错误如下:
javax.naming.CommunicationException [Root exception is java.net.ConnectException: t3://localhost:7007: Destination unreachable; nested exception is: 
    java.net.ConnectException: Connection refused: connect; No available router to destination]
    at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:
40)
    at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:
783)
    at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:
367)
    at weblogic.jndi.Environment.getContext(Environment.java:
315)
    at weblogic.jndi.Environment.getContext(Environment.java:
285)
    at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:
117)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:
667)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:
288)
    at javax.naming.InitialContext.init(InitialContext.java:
223)
    at javax.naming.InitialContext.
<init>(InitialContext.java:197)
    at com.etong.framework.datasource.TestJndi.testJndi(TestJndi.java:
21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
    at java.lang.reflect.Method.invoke(Method.java:
597)
    at junit.framework.TestCase.runTest(TestCase.java:
168)
    at junit.framework.TestCase.runBare(TestCase.java:
134)
    at junit.framework.TestResult$
1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:
128)
    at junit.framework.TestResult.run(TestResult.java:
113)
    at junit.framework.TestCase.run(TestCase.java:
124)
    at junit.framework.TestSuite.runTest(TestSuite.java:
232)
    at junit.framework.TestSuite.run(TestSuite.java:
227)
    at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:
76)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:
38)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:
386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
196)
Caused by: java.net.ConnectException: t3:
//localhost:7007: Destination unreachable; nested exception is: 
    java.net.ConnectException: Connection refused: connect; No available router to destination
    at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:
203)
    at weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:
153)
    at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:
352)
     
27 more
Caused by: java.rmi.ConnectException: Destination unreachable; nested exception is: 
    java.net.ConnectException: Connection refused: connect; No available router to destination
    at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:
464)
    at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:
315)
    at weblogic.rjvm.RJVMManager.findOrCreateRemoteInternal(RJVMManager.java:
251)
    at weblogic.rjvm.RJVMManager.findOrCreate(RJVMManager.java:
194)
    at weblogic.rjvm.RJVMFinder.findOrCreateRemoteServer(RJVMFinder.java:
225)
    at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:
188)
     
29 more


换成 t3://localhost:7001
测试成功.看来不懂就到网上乱COPY代码,还是不行的

 

我已经在配置文件里配置了context.java.naming.factory.initial,而在这里还提示这个错误
关键看这里

Error initializing JtaTransactionConfig while looking up UserTransaction (javax.transaction.UserTransaction). Cause: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial


jvm里加上一个参数,测试一下

-Djava.naming.factory.initial=weblogic.jndi.WLInitialContextFactory


运行通过

这个参数在:右键项目--Run as --Open Run Dialog--ArgumentsVM arguments中添加即可


posted @ 2009-08-23 10:41 蒋德 阅读(5156) | 评论 (1)编辑 收藏

2008年12月17日 #

一直用Xdoclet 来管理项目的配置文件,今天用Myeclipse 建新了一个工程,使用Myeclipse 的Strtus1.2的相关包,发现生成相关的配置文件中<action-mappings> 部分竟然是空白的,百思不得其解,反复测试后,发现取消Myeclipse 的Strtus1.2的相关包,使用以前的Struts .jar又可以生成.
 记录下,日后再找到原因

到google 里一找,发现自己几年前还记录了这个,2009年我又遇到了这个问题
发现,在xdoclet 里生成struts的配置文件时,一定要在lib下面存在
struts.jar
commons-collections-3.0.jar
commons-digester.jar
commons-logging-1.0.4.jar
否则就可能不生成,也不出错.

莫名其妙的.

posted @ 2008-12-17 20:54 蒋德 阅读(135) | 评论 (0)编辑 收藏

2008年6月12日 #

2008年真是个多事之秋,从年初的雪灾,股灾 到 3.15事件,4.28撞车,5.12 纹川地震,水灾一次又一次的袭击着中国人民.
网络世界也不例外,6月份的端午节注定是个难忘的日子.
1前言
     **** 旗下的网站随着电子商务的大潮流越来越受领导的重视,商务的成功运作,铺天盖地的广告投入,让这个这不知名的小网站一下子变得重要起来,网站作为集团公司客户关怀的主要渠道,已被人悄悄的盯上了.一场悄无声息的战争就这样子开始了

2发现病毒
        6月5号,这几天心情不错,工作交接的也算顺利.10点左右,前台的编辑人员给我发来消息,运营部门要求加入统计的JS脚本代码,其实我最烦这些工作了,统计的JS代码谁敢保证没有问题呢?网站一但出现不稳定的时候,我就要冒冷汗,何况在这之前网站已出现过好几次问题了.ARP攻击.DDOS攻击.一轮接一轮.想些这些就害怕.电话再次沟通,确认.我在服务器上加载了关于统计的JS代码.接下来无事,我继续着交接文档
        从食堂回来很开心,呵呵,一边吃饭一边享受美丽风景的机会是不多的.在公司的猪圈里胡乱的吹水.天花乱坠的.TNND,也不知群主怎么想的,好好的名不起,偏起了个猪圈.不过在这个群里聊天还是很开心的.聊累了就睡,也不用去理会什么.
          一觉醒来,习惯性的打开网站,卡巴斯基猛的跳出个窗口提示恶意的js 我当时还没回过神来,确认后敢紧打电话确认前台的静态页面是否有发布.确认后回想今天的修改,就加载了统计的JS,不会这么巧吧,难道是因为这个中招了?我敢紧要求前台发布人员删除相关的JS代码.
结果依旧.卡巴斯基欢快的提示着恶意JS ,然后一个个的进行阻止. 从这点来看,我还是很中意卡巴斯基这个软件的.果然不5分钟,运营部门来电话了.说网站全面出现病毒.要求处理.当然我就急了.以现在的访问量,要是不尽快处理,不知多少用户会受到影响.我电话通知发布系统的同事,要求重新发布新的静态页面.同时通知***部门的项目负责人.要求对系统进行查毒.
        一切都在紧张有顺的进行着.我等待着结果,同时也在想,到底是哪能儿出错了呢?统计的JS?系统被人攻破?半小时后,***部门反馈消息服务器没有发现病毒.我的心随之绷紧了.如果服务器没有发现病毒,就可能是WEB应用上有问题了.我查找今天刚发布的文件.好多.不确定具体在哪儿出问题了.只能一个一个的去查看源码.网站上病毒提示依然存在.急得我就像热窝里的蚂蚁团团转.文件一个一个的对比,检查JS里的可疑代码.2个小时过去了,没有一点进展.还是没有发现源头.突然想到,整站都出现了恶意的JS代码,肯定是共公文件出问题了.我电话询问前台发布人员,公共JS存放目录.果然发现有个文件被修改了.马上改了回来,卡巴斯基停止的报告.挂码被清除出去了.终于松了一口气,收拾东西回家.

3更换服务器
    6号早上,好不容易的挤上64路车,自从取消上沙车站后,在下沙上64路就难了.站的位置要不是好.上车都是个问题
4事件升级
5网安公司
6切按平台

posted @ 2008-06-12 10:50 蒋德 阅读(264) | 评论 (0)编辑 收藏

2008年4月26日 #

这段时间在开发eclipse plugin 时候,要在生成项目的时候自动增加library

其JAVA代码如下:
增加src :

IPath path = new Path("src/main/java");
JavaCore.newSourceEntry(fCurrProject.getFolder(path).getFullPath());

增加con

IPath aopPath = new Path("melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING20_AOP");
IClasspathEntry lib1 
= JavaCore.newContainerEntry(aopPath);


<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    
<classpathentry kind="src" path="src/main/java"/>
    
<classpathentry kind="src" path="src/test/java"/>
    
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING20_AOP"/>
    
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING20_CORE"/>
    
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING20_DAO"/>
    
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING20_WEB"/>
    
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/antlr.jar"/>
    
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tecore.jar"/>
    
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"/>
    
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
</classpath>
posted @ 2008-04-26 10:41 蒋德 阅读(908) | 评论 (0)编辑 收藏

2008年3月20日 #

在用Struts 进行开发的时候,为了项目的并行,会有多个配置文件。
如 struts-a.xml ; struts-b,xml ; struts-c.xml ;  
这么多的配置文件如果都要手工配置到web.xml文件中,其实是很麻烦的。那么如何让他自己动加载到struts-*.xml呢?
如下:

<servlet>
        
<servlet-name>action</servlet-name>
        
<servlet-class>com.allcom.base.util.AutoActionServlet</servlet-class>
        
<init-param>
            
<param-name>config</param-name>
            
<param-value>/WEB-INF/struts-*.xml</param-value>
        
</init-param>
        
<init-param>
            
<param-name>debug</param-name>
            
<param-value>3</param-value>
        
</init-param>
        
<init-param>
            
<param-name>detail</param-name>
            
<param-value>3</param-value>
        
</init-param>
        
<load-on-startup>5</load-on-startup>
    
</servlet>



在这里面,我用了通配符,所有由struts-开头的.xml文件都可以进行自动加载
com.allcom.base.util.AutoActionServlet
其源码为:

package com.allcom.base.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;

import com.allcom.base.core.module.PropertyManager;
/**
 * 
@author <a href="mailto:jdskyy@163.com">Jdskyy</a>
 * 自动集成Struts 多个配置文件
 * 
 * 
*/

public class AutoActionServlet extends org.apache.struts.action.ActionServlet {
    
protected void initOther()throws ServletException {
         String value 
= getServletConfig().getInitParameter("config");
         
if(value != null && value.contains("*")){
             List xmlfilelist 
= new ArrayList();    
             String path 
= PropertyManager.getProperty("WebPath")+"WEB-INF";
             File file 
= new File(path);
             
if(!file.exists()) return;
             
if(!file.isDirectory()) return
             String[] tempList 
= file.list();
             File temp 
= null;
             
for(int i = 0; i < tempList.length; i++
             
{
                 
if(path.endsWith(File.separator))
                     temp 
= new File(path + tempList[i]);
                 
else 
                     temp 
= new File(path + File.separator + tempList[i]);
                    
                 
if(temp.isFile()) {
                     String xmlFileName
=temp.getName();
                     
if(xmlFileName.startsWith("struts-")){
                         System.out.println(xmlFileName);
                         xmlfilelist.add(
"/WEB-INF/"+xmlFileName);
                     }

                 }

             }

             String configStr 
=ListTOString(xmlfilelist);
             config 
= configStr;
        }

    }

    
    
public static String ListTOString(List ids) {
        StringBuffer listBufferStr 
= new StringBuffer();
        
for(int i=0; i <ids.size() ;i++){
            
if(i==0){
                listBufferStr.append(ids.get(i));
            }
else{
                  listBufferStr.append(
","+ids.get(i));
            }

        }

        
return listBufferStr.toString();
    }

}


经过AutoActionServlet的转换,Strtus  就可以自动识别配置文件了

posted @ 2008-03-20 09:11 蒋德 阅读(1438) | 评论 (2)编辑 收藏

2008年3月19日 #

DWR 常用功能

转换指定的属性,如下只转换:quarterId,和quarterName两个属性

<convert converter="bean" match="com.allcom.panel.persist.Quarter">
          
<param name="include" value="quarterId,quarterName"/>
</convert>


只包含指定的方法 <include method="createFavorite"/>

<create creator="spring"  javascript="favoriteDao">
           
<param name="beanName" value="favoriteDao"/>
           
<include method="createFavorite"/>
</create>
posted @ 2008-03-19 18:16 蒋德 阅读(202) | 评论 (0)编辑 收藏

 

String keyWord = "字符1 字符2 字符3";
if(null!=keyWord && !"".equals(keyWord)){
    String keyWords[] 
= keyWord.split("\\s+");
    
for (int p=0;p<keyWords.length;p++){
        String key 
= keyWords[p];
        System.out.println(
"分隔后的字符"+key);
    }

}
posted @ 2008-03-19 18:14 蒋德 阅读(218) | 评论 (0)编辑 收藏

2008年3月12日 #

复选框的JSP页面

 <form action="${ctx}/merchant/product.do?method=delete" name="outform" id="outform" method="post">
                   
<ec:table var="productForm" items="Products"
                    action
="${ctx}/merchant/product.do" showPagination="true" showExports="true" showStatusBar="true" sortable="true" filterable="false" rowsDisplayed="15"
                    retrieveRowsCallback
="org.extremecomponents.table.callback.LimitCallback" 
                    filterRowsCallback
="org.extremecomponents.table.callback.LimitCallback"   
                    sortRowsCallback
="org.extremecomponents.table.callback.LimitCallback" form="outform">
                    
<ec:exportXls fileName="productList.xls" tooltip="toolbar.text.xls" />
                    
<ec:row>
                       
<ec:column property="name" title="选择" style="width:5px" filterable="false"  width="5%" sortable="false"> 
                        
<input type="checkbox" name="productID"  value="${productForm.productId}"/> 
                        
</ec:column> 
                        
<ec:column property="productName" title="PRODUCT.productName" width="10%"/></ec:row>
                
</ec:table>
                
<input type="submit" value="批量删除" name="submitData">
                
</form>

注意的地方
     1: <form action="${ctx}/merchant/product.do?method=delete" name="outform" id="outform" method="post">
     2:  <ec:table ...... form="outform" >
     3:   <ec:column property="name" title="选择" style="width:5px" filterable="false"  width="5%" sortable="false"> 
                     <input type="checkbox" name="productID"  value="${productForm.productId}"/> 
              </ec:column> 
              </form>
     
  

posted @ 2008-03-12 18:21 蒋德 阅读(939) | 评论 (0)编辑 收藏

2008年3月10日 #








posted @ 2008-03-10 10:54 蒋德 阅读(258) | 评论 (0)编辑 收藏

 









posted @ 2008-03-10 10:52 蒋德 阅读(413) | 评论 (1)编辑 收藏

仅列出标题  下一页