廣告聯播
2014年8月14日 星期四
如何在 eclipse 利用 maven 建立 struts2 並在 eclipse internal runtime Server: Tomcat 作開發環境測試
主要目的:如何在 eclipse 利用 maven 建立 struts2 並在 eclipse internal runtime Server: Tomcat 作開發環境測試
平台:
eclipse:
Version: Kepler Service Release 2
Build id: 20140224-0627
maven:Maven Integration for Eclipse (Luna and newer) 1.5
tomcat:apache-tomcat-7.0.52_x64
java:jdk1.7.0_45_x64
jboss:JBoss EAP 6.2.0.GA
step01:建立一個 struts2-archetype-blank 的 maven 專案
可以按一下 Add Archetype,建立一個空的 Struts2 專案,相關欄位資訊可以查:http://struts.apache.org/release/2.2.x/docs/struts-2-blank-archetype.html
Step02:轉換成為 Dynamic Web project
選擇此專案 guEBS 按下滑鼠右鍵,選擇 Properties 裡的 Project Facets ,按下 Covert to faceted form...
先將 java 的版本改為 1.7 ,再將 Dynamic Web project 的 check box 打勾,此時下方會出現 "Further configuration available...",Content directory 原本是 WebContent ,修改為 src/main/webapp。
再到 Deployment Assembly 將 Maven Dependencies 加入,然後按 Apply -> ok。
Step03:Deploy to Internal runtime Server:Tomcat 測試
執行 Maven build 時, 應該在 target 目前下會產生 guEBS-1.0.0-SNAPSHOT.war,這個檔直接可以佈署在 JBoss 下執行。
(繼續閱讀...)
2009年5月10日 星期日
利用 Lambda Probe 來觀察 JNDI 的 DataSource Connection Pools
在寫 Java 程式時, 利用 JNDI 來連接資料庫, 是一個非常好的方法, JNDI 的設定, 請參考: [JNDI] Java + Tomcat + MySQL 的連結設定 但是新手程式設計師常常建立了 DataSource 的 Connection , 在取完資料庫後, 卻又常常忘了關閉這一條 connection . 導致資料庫連接池 ( DataSource Connection Pools ) 不夠使用, 而整個 Application Server 當住了.
這有一個不錯的工具 Lambda Probe , 可以讓程式設計師來觀察程式撰寫的過程中, 是否有 Connection 忘了關閉的情況. 而 Lambda Probe 目前有支援 Tomcat & JBoss.
環境:
Tomcat : 6.0.14
Lambda Probe: LambdaProbe 1.7b, BINARIES (解開的檔案放在 D:\probe)
Step 01:
從 Lambda Probe 下載 LambdaProbe 1.7b, BINARIES , 並解開放在 D:\probe
Step 02:
修改 Tomcat 的 server.xml , tomcat-users.xml 分別如下:

server.xml
<Context docBase="D:/probe" path="/probe" privileged="true"/>tomcat-users.xml
<role rolename="admin"/>
<user username="admin" password="1234" roles="admin,manager"/>Step 03:
重啟 Tomcat
Step 04:
進入: http://localhost:8080/probe
輸入admin,1234

Step 05:
點選 Data Sources 的頁次, 就可以查看 DataSource Connection Pools 的狀況

參數說明:
在 Data Sources 頁次中的 M, E , B 分別為
M: Total max. 連接池最大的連接數目
E: Total estab. 現行已建立過的連接(connections) 數目
B: Total busy 目前的連接數
2009年5月7日 星期四
[FCKeditor] 用 Java Taglib 使用 FCKeditor
FCKeditor 是所見即所得(WYSIWYG)的線上編輯器, 支援多國語言, 多種瀏覽器支援, 可更換SKIN,還可以用JavaScript控制按鈕,功能十分多樣化,外掛的功能也是十分強大,支援瀏覽器管理檔案...等多樣化外掛。
支援語言: ASP.Net, ASP, ColdFusion, PHP, Java, Active-FoxPro, Lasso, Perl, Python
支援流覽器: IE, FireFox, Safari, Opera, Google Chrome, Camino
支援平台: MS Windows , MAC , Linux
版權: under the GPL, LGPL and MPL open source licenses
在 Java 的平台上有一個很好用的工具 Taglib , 可以讓你的 jsp 程式簡單化.配置如下
FCKeditor: FCKeditor_2.6.4.zip
FCKeditor.Java: fckeditor-java-2.4.1-bin.zip
FCKeditor.Java 文件參考: http://java.fckeditor.net/
SLF4j: slf4j-1.5.6.zip
Application Server: Tomcat 6.x.x
step01:
在 WebContent 目錄下建立一個目錄 fckeditor , 並將 FCKeditor_2.6.4.zip 解開的資料放在這個目錄下.
step02:
解開 fckeditor-java-2.4.1-bin.zip , 將 fckeditor-java-core-2.4.1.jar, 及 lib 目錄下的三個檔案 commons-fileupload-1.2.1.jar, commons-io-1.3.2.jar, slf4j-api-1.5.2.jar , 複製到 WEB-INF\lib
step03:
解開 slf4j-1.5.6.zip , 將slf4j-api-1.5.6.jar, slf4j-simple-1.5.6.jar 複製到 WEB-INF\lib
step04:
在 WEB-INF\web.xml 檔增加下列程式碼
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>net.fckeditor.connector.ConnectorServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern> /fckeditor/editor/filemanager/connectors/*
</url-pattern>
</servlet-mapping>step05:
在 WEB-INF 目錄下增加一個檔案 FCKeditor.tld , 內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<taglib 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-jsptaglibrary_2_0.xsd"
version="2.0">
<description>
The FCKeditor Tag Library offers a very convenient way to create
several FCKeditor instances with different configurations.
Additionally, you can check for user-based capabilities.
</description>
<display-name>FCKeditor Tag Library</display-name>
<tlib-version>2.4</tlib-version>
<short-name>FCK</short-name>
<uri>http://java.fckeditor.net</uri>
<tag>
<description>
Creates a FCKeditor instance with the given parameters. Any
parameter except instanceName which is empty or contains
whitespaces only will be ignored.
</description>
<display-name>editor</display-name>
<name>editor</name>
<tag-class>net.fckeditor.tags.EditorTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>
The unique instance name under which the editor can be
retrieved through the API.
</description>
<name>instanceName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
Width of the FCKeditor instance in the browser window.
</description>
<name>width</name>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
Height of the FCKeditor instance in the browser window.
</description>
<name>height</name>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
The toolbar set which shall be displayed to the user.
</description>
<name>toolbarSet</name>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
The path/folder in which the editor is deployed under
the given context. The context path will be attached
automatically. (e.g. '/fckeditor')
</description>
<name>basePath</name>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
Passes any content to the FCKeditor document. Use the
jsp:attribute tag for large inline content. \r, \n, and
\t will be truncated.
</description>
<name>value</name>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<example><![CDATA[
<FCK:editor instanceName="editorDefault" height="500px" />]]>
</example>
</tag>
<tag>
<description>
Sets a config property of the editor to the supplied value.
You may provide any attribute you want for the editor. Set
at least one attribute per tag or several attributes with
one tag. This tag can only be nested within an editor tag.
For all configuration options click
<![CDATA[<a href="http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options">here</a>]]>.
</description>
<display-name>config</display-name>
<name>config</name>
<tag-class>net.fckeditor.tags.ConfigTag</tag-class>
<body-content>empty</body-content>
<dynamic-attributes>true</dynamic-attributes>
<example>
<![CDATA[
<FCK:config SkinPath="/skins/silver/" AutoDetectLanguage="true" />]]>
</example>
</tag>
<tag>
<description>
Displays session-dependent and compatibility-related
information. This tag is intended for developers only.
Response messages cannot be localized, they are English
only.
</description>
<display-name>check</display-name>
<name>check</name>
<tag-class>net.fckeditor.tags.CheckTag</tag-class>
<body-content>empty</body-content>
<attribute>
<description>
Provide the feature name you want to check. Valid
features are [FileUpload, FileBrowsing,
CompatibleBrowser]
</description>
<name>command</name>
<required>true</required>
<type>java.lang.String</type>
</attribute>
<example><![CDATA[
<FCK:check command="FileUpload" />
<FCK:check command="CompatibleBrowser" />]]>
</example>
</tag>
</taglib>
step06:
建立一個 fck.jsp 來測試, 程式碼如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/FCKeditor.tld" prefix="FCK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="show.jsp" method="post" target="_blank">
<FCK:editor instanceName="fckEdit" width="700" height="500" toolbarSet="Default" />
<input type="submit" value="Submit">
</form>
</body>
</html>
成果如下圖:

fckeditor-java-2.4.1 的設定比較簡便, 就連上載檔案, 也只要在step04: 設定好 servlet : Connector 就可以了. 不需要太繁瑣. 不過若要上載檔案, 不要忘了要在 classpath 建立一個檔案 fckeditor.properties , 內容如下:
fckeditor.toolbarSet=Basic
connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl
connector.userFilesPath=/userfiles
connector.resourceType.file.extensions.allowed=txt|doc
connector.resourceType.image.extensions.allowed=jpg|png這樣才不會有問題. 參數說明:
connector.userFilesPath : 是伺服器上要存放檔案的地方.如 /userfiles
connector.resourceType.file.extensions.allowed : 可以限制上傳到/userfiles/file 目錄的附加檔名有那些
connector.resourceType.image.extensions.allowed: 可以限制上傳到/userfiles/image 目錄的附加檔名有那些
因為上載的檔案只能存在這個 application WEBcontent 的目錄內, 所以若將 java 打包成 war 檔在 JBoss 上使用, 則會有問題.
2009年1月8日 星期四
[Tomcat] apache-tomcat-6.x.zip 的起動方式
Tomcat 在 Window 的平台可以不用安裝就可以起動執行. 從 http://tomcat.apache.org/index.html 下載 apache-tomcat-6.x.x.zip 的壓縮檔, 解開後執行 %CATALINA_HOME%\bin\startup.bat 卻沒啟動 ? 為何?
正確的步驟應如下:
1. 將 http://tomcat.apache.org/index.html 下載 apache-tomcat-6.x.x.zip 的壓縮檔解壓到 C:\AppServ\apache-tomcat-6.0.14
2. 在 %CATALINA_HOME%\bin 目錄新增一個檔案 project_start.bat 內容如下:
@echo off
set CATALINA_HOME=C:\AppServ\apache-tomcat-6.0.14
rem JAVA_HOME must point to a full JSDK, not just a JRE
set JAVA_HOME=D:\Progs\jdk1.6.0_07
rem Quite possibly gratuitous
set PATH=%JAVA_HOME%\jre\bin;%JAVA_HOME%\bin;%PATH%
rem Adjust the following heap settings as necessary
set JAVA_OPTS=-server -Xms256M -Xmx256M -Djava.awt.headless=true -Dwt.context.defaultLocalResourcesOnly=true
rem Enable local JMX connections in Java 5
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote
rem Un-rem next line to enable debugger attaching to this instance of Tomcat
rem set JAVA_OPTS=%JAVA_OPTS% -Xnoagent -Xdebug -Xrunjdwp:transport=dt_shmem,address=tomcat,server=y,suspend=n
"%CATALINA_HOME%\bin\startup.bat"
3. 編輯 %CATALINA_HOME%\conf\server.xml , 在設定檔區間要寫入您專案的名字
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
[ JAVA 的專案名稱要放在這裡 ]
</Host>
如下:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
<Context docBase="D:/myProj" path="/myProj" reloadable="true" crossContext="true" source="org.eclipse.jst.j2ee.server:myProj"/>
</Host>
這樣就可以執行了
2008年11月14日 星期五
[JNDI] Java + Tomcat + MySQL 的連結設定
環境:
Web Server: apache-tomcat-6.0.14
DB Version: MySQL 5.0.45
DB : test
Table: users(username varchar(30),password varchar(30))
JDBC Driver: mysql-connector-java-5.1.7-bin.jar
JAVA: jdk1.6.0_07
在Web步驟如下:
Step 1: Copy MySQL Connector/J 的 JAR 檔
將 mysql-connector-java-5.1.7-bin.jar 複製到 $TOMCAT_HOME/lib
Step 2:在 $TOMCAT_HOME/conf/server.xml 的 <Context></Context> 中加入下列的參數
Step 3: 撰寫一個網頁 MySQLConnTest.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="com.mysql.*,java.util.*,javax.naming.*,java.sql.*,javax.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Context ctx = new InitialContext();
String strLookup = "java:comp/env/jdbc/MySQLDS01";
DataSource ds =(DataSource) ctx.lookup(strLookup);
Connection con = ds.getConnection();
Statement smt = con.createStatement();
String sql = "";
ResultSet rs = null;
sql = "SELECT * FROM users";
rs = smt.executeQuery(sql);
while(rs.next())
{
out.println(rs.getString(1));
out.println(rs.getString(2));
}
%>
</body>
</html>
這樣就可以利用 JNDI 的方式連到 MySQL , 並在網頁中顯示資料庫test中表格users裡的資料.
若是純以 Java Code 來執行連結MySQL , 則程式碼如下:
package com.demos;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class MySQLConnTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn = null;
String Server_IP = "127.0.0.1";
try {
Class.forName("com.mysql.jdbc.Driver");
String sql = "";
conn = DriverManager.getConnection("jdbc:mysql://" + Server_IP
+ ":3306/test", "username", "password");
sql = "select * from users";
// Statement stmt =
// conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
// ResultSet.CONCUR_READ_ONLY);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
System.out.println(rs.getString("userName"));
System.out.println(rs.getString("password"));
} else {
System.out.print("Cound not find data in test of MySQL");
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
} finally {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
-
From: Polin Wei Hyperion Interactive Reporting 是 Oracle BI (Business Intelligence Suite Enterprise Edition Plus)系統中的模組之一,它可以輕鬆的幫你製作 Repo...
-
From: Polin Wei 環境: OS: Windows Server 2k3 + SP2 DB: Oracle XE Hyperion : 9.3.1 step 01: 準備 Windows Server 作業平台 將 Windows Server 2k3 + SP2 依...
-
From: Polin Wei 現在的即時通訊 MSN 、Skype ... 等工具,都具備有檔案傳輸的功能,小檔案或許沒問題,但若要傳個 10M 以上的檔,那連用 E-Mail 寄送可能都會無法達成。 可以嚐試在自己電腦中架設 FTP Server ( FTP 伺服器)...