Thursday, December 2, 2010
Wednesday, December 1, 2010
Monday, November 29, 2010
Adding one month to SYSDATE
Sunday, November 28, 2010
Thursday, November 18, 2010
SEO Tools เครื่องมือต่าง ๆ ในการทำ SEO
Monday, May 10, 2010
Grails remote jQuery form validation
<script type="text/javascript"> $(function (){ $("#form").validate({ rules: { 'address.postalCode': { required: true }, }, messages: { 'address.postalCode': { required: "Please enter a postal code." } } }); }); </script> <g:form method="post" action="register" name="form"> <input type="text" name="address.postalCode" id="postalCode" /> <input type="submit" value="Proceed" /> </g:form> |
Grails Return JSON
Domain Class:
class MyDomain {
String name
String address
String gender
}
Controller Class :
class MyController {
def someaction =
{
List myDomains = MyDomain.findAllByGender(params.gender)
<em>/*Let say 5 objects are retrieved*/</em>
render myDomains as JSON
}
}
The above code in action will render a JSON string in the following format:
[
{
"name" : "John",
"address" : "New York",
"gender" : "Male"
},
{
"name" : "Rob",
"address" : "Indonasia",
"gender" : "Male"
},
{
"name" : "Shayam",
"address" : "New Delhi",
"gender" : "Male"
},
{
"name" : "Chang",
"address" : "Thailand",
"gender" : "Male"
},
{
"name" : "Ali",
"address" : "London",
"gender" : "Male"
}
]
following script would be writtent on the client Side (in the GSP):
|
The HTML code would be like this :
<div id="someid">
Click for JSON Response
</div>
<table id="mytable">
<!–empty table –>
</table>
When you click on the displayed text the html page would become like following:
<div id="someid">
Click for JSON Response
</div>
<table id="mytable">
<tr>
<td>John</td>
<td>New York</td>
<td>Male</td>
</tr>
<tr>
<td>Rob</td>
<td>Indonasia</td>
<td>Male</td>
</tr>
<tr>
<td>Shayam</td>
<td>New Delhi</td>
<td>Male</td>
</tr>
<tr>
<td>Chang</td>
<td>Thailand</td>
<td>Male</td>
</tr>
<tr>
<td>Ali</td>
<td>London</td>
<td>Male</td>
</tr>
</table>
any kind of suggestions and comments are welcome……
Groovy List<Integer>
List<Integer> list = [5,6,7,8]
list.each({line -> println line})
list.each({println it})
Basic Groovy Lang…
println '######################## List ##########################\n'
List<Integer> list = [1,2,3,4,5,6,7,7,6,5,6,7,5,6,5]
println 'value list[0] is '+list[0]
println 'value list[3] is '+list[3]
println 'value list[8] is '+list[8]
println 'size = '+list.size()
println '######################## MAP ##########################\n'
Map map = [:]
def map2 = ["Jim":"Knopf", "Thomas":"Edison"]
println map2["Jim"]
map2["Test"] = "Tester"
println map2["Test"]
println '######################## For ##########################\n'
for (i in 0..9) {
println ("Hello $i" )
}
println '######################## Defines a string with special signs ##########################\n'
// Defines a string with special signs
def text = "John Jimbo jingeled happily ever after"
// Every word must be followed by a nonword character
// Match
if (text==~/(\w*\W+)*/){
println "Match was successful"
} else {
println "Match was not successful"
}
// Every word must be followed by a nonword character
// Find
if (text=~/(\w*\W+)*/){
println "Find was successful"
} else {
println "Find was not successful"
}
if (text==~/^J.*/ ){
println "There was a match"
} else {
println "No match found"
}
def newText = text.replaceAll(/\w+/, "hubba")
println newText
Tuesday, May 4, 2010
Crate Grails
#1
C:\>grails create-app MyApp
Welcome to Grails 1.2.1 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: C:\grails-1.2.1
จากนั้น
#2
grails tomcat
Found events script in plugin tomcat
Created Grails Application at C:\/MyApp
C:\>cd MyApp
#3
C:\MyApp>grails run-app
Welcome to Grails 1.2.1 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: C:\grails-1.2.1
#4 ทดสอบ
http://localhost:8080/MyApp
Monday, May 3, 2010
Sunday, April 25, 2010
global-web-application.xml deployment-version="10.1.3.3.0"
<?xml version="1.0"?>
<orion-web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-web-10_0.xsd" deployment-version="10.1.3.3.0"
deployment-time="1272262623732"
jsp-cache-directory="./persistence"
jsp-cache-tlds="off"
jsp-taglib-locations=""
temporary-directory="./temp"
default-mime-type="application/octet-stream"
servlet-webdir="/servlet"
context-root="/"
schema-major-version="10" schema-minor-version="0" >
<mime-mappings path="./mime.types" />
<!-- Uncomment this element to control web application class loader behavior.
<web-app-class-loader search-local-classes-first="true" include-war-manifest-class-path="true" />
-->
<web-app>
<servlet>
<servlet-name>jsp</servlet-name>
<display-name>jsp</display-name>
<servlet-class>oracle.jsp.runtimev2.JspServlet</servlet-class>
<init-param>
<param-name>emit_debuginfo</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>reduce_tag_code</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>extra_imports</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>main_mode</param-name>
<param-value>recompile</param-value>
</init-param>
<init-param>
<param-name>debug_mode</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>precompile_check</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>forgive_dup_dir_attr</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xml_validate</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>tag_reuse_default</param-name>
<param-value>compiletime</param-value>
</init-param>
<init-param>
<param-name>external_resource</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>static_text_in_chars</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>rmi-tunnel</servlet-name>
<display-name>rmi-tunnel</display-name>
<servlet-class>oracle.oc4j.rmi.tunnelling.TunnelledRmiServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>jms</servlet-name>
<display-name>jms</display-name>
<servlet-class>com.evermind.server.jms.HTTPJMSRequestHandler</servlet-class>
</servlet>
<servlet>
<servlet-name>ssi</servlet-name>
<display-name>ssi</display-name>
<servlet-class>com.evermind.server.http.SSIServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>cgi</servlet-name>
<display-name>cgi</display-name>
<servlet-class>com.evermind.server.http.CGIServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>perl</servlet-name>
<display-name>perl</display-name>
<servlet-class>com.evermind.server.http.CGIServlet</servlet-class>
<init-param>
<param-name>interpreter</param-name>
<param-value>perl</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>php</servlet-name>
<display-name>php</display-name>
<servlet-class>com.evermind.server.http.CGIServlet</servlet-class>
<init-param>
<param-name>interpreter</param-name>
<param-value>php</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>rmi-tunnel</servlet-name>
<url-pattern>*.rmiTunnel</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jms</servlet-name>
<url-pattern>/jms</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.JSP</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.sqljsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.SQLJSP</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>*.cgi</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>perl</servlet-name>
<url-pattern>*.pl</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>*.php3</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>*.phtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>wml</extension>
<mime-type>text/vnd.wap.wml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pbm</extension>
<mime-type>image/x-portable-bitmap</mime-type>
</mime-mapping>
<mime-mapping>
<extension>snd</extension>
<mime-type>audio/basic</mime-type>
</mime-mapping>
<mime-mapping>
<extension>tar</extension>
<mime-type>application/x-tar</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xsd</mime-type>
</mime-mapping>
<mime-mapping>
<extension>eps</extension>
<mime-type>application/postscript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>qt</extension>
<mime-type>video/quicktime</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pnm</extension>
<mime-type>image/x-portable-anymap</mime-type>
</mime-mapping>
<mime-mapping>
<extension>rtf</extension>
<mime-type>application/rtf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>tsv</extension>
<mime-type>text/tab-separated-values</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ras</extension>
<mime-type>image/x-cmu-raster</mime-type>
</mime-mapping>
<mime-mapping>
<extension>movie</extension>
<mime-type>video/x-sgi-movie</mime-type>
</mime-mapping>
<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>
<mime-mapping>
<extension>sgm</extension>
<mime-type>text/x-sgml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ice</extension>
<mime-type>x-conference/x-cooltalk</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ram</extension>
<mime-type>audio/x-pn-realaudio</mime-type>
</mime-mapping>
<mime-mapping>
<extension>cpt</extension>
<mime-type>application/mac-compactpro</mime-type>
</mime-mapping>
<mime-mapping>
<extension>mpga</extension>
<mime-type>audio/mpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>cdf</extension>
<mime-type>application/x-netcdf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>mp2</extension>
<mime-type>audio/mpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>aiff</extension>
<mime-type>audio/x-aiff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>dvi</extension>
<mime-type>application/x-dvi</mime-type>
</mime-mapping>
<mime-mapping>
<extension>aifc</extension>
<mime-type>audio/x-aiff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>rgb</extension>
<mime-type>image/x-rgb</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gif</extension>
<mime-type>image/gif</mime-type>
</mime-mapping>
<mime-mapping>
<extension>wrl</extension>
<mime-type>x-world/x-vrml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pgm</extension>
<mime-type>image/x-portable-graymap</mime-type>
</mime-mapping>
<mime-mapping>
<extension>dcr</extension>
<mime-type>application/x-director</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>application/x-javascript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jnlp</extension>
<mime-type>application/x-java-jnlp-file</mime-type>
</mime-mapping>
<mime-mapping>
<extension>dir</extension>
<mime-type>application/x-director</mime-type>
</mime-mapping>
<mime-mapping>
<extension>lha</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ps</extension>
<mime-type>application/postscript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>vrml</extension>
<mime-type>x-world/x-vrml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>avi</extension>
<mime-type>video/x-msvideo</mime-type>
</mime-mapping>
<mime-mapping>
<extension>man</extension>
<mime-type>application/x-troff-man</mime-type>
</mime-mapping>
<mime-mapping>
<extension>lzh</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<mime-mapping>
<extension>bin</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpeg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>doc</extension>
<mime-type>application/msword</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jar</extension>
<mime-type>application/java-archive</mime-type>
</mime-mapping>
<mime-mapping>
<extension>htm</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>tex</extension>
<mime-type>application/x-tex</mime-type>
</mime-mapping>
<mime-mapping>
<extension>src</extension>
<mime-type>application/x-wais-source</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ent</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>etx</extension>
<mime-type>text/x-setext</mime-type>
</mime-mapping>
<mime-mapping>
<extension>aif</extension>
<mime-type>audio/x-aiff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xwd</extension>
<mime-type>image/x-xwindowdump</mime-type>
</mime-mapping>
<mime-mapping>
<extension>t</extension>
<mime-type>application/x-troff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jad</extension>
<mime-type>text/vnd.sun.j2me.app-descriptor</mime-type>
</mime-mapping>
<mime-mapping>
<extension>mpeg</extension>
<mime-type>video/mpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>shar</extension>
<mime-type>application/x-shar</mime-type>
</mime-mapping>
<mime-mapping>
<extension>roff</extension>
<mime-type>application/x-troff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>skt</extension>
<mime-type>application/x-koan</mime-type>
</mime-mapping>
<mime-mapping>
<extension>skp</extension>
<mime-type>application/x-koan</mime-type>
</mime-mapping>
<mime-mapping>
<extension>skm</extension>
<mime-type>application/x-koan</mime-type>
</mime-mapping>
<mime-mapping>
<extension>cpio</extension>
<mime-type>application/x-cpio</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xpm</extension>
<mime-type>image/x-xpixmap</mime-type>
</mime-mapping>
<mime-mapping>
<extension>sv4cpio</extension>
<mime-type>application/x-sv4cpio</mime-type>
</mime-mapping>
<mime-mapping>
<extension>skd</extension>
<mime-type>application/x-koan</mime-type>
</mime-mapping>
<mime-mapping>
<extension>dtd</extension>
<mime-type>text/dtd</mime-type>
</mime-mapping>
<mime-mapping>
<extension>sgml</extension>
<mime-type>text/x-sgml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>latex</extension>
<mime-type>application/x-latex</mime-type>
</mime-mapping>
<mime-mapping>
<extension>Z</extension>
<mime-type>application/x-compress</mime-type>
</mime-mapping>
<mime-mapping>
<extension>cat</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>zip</extension>
<mime-type>application/zip</mime-type>
</mime-mapping>
<mime-mapping>
<extension>wmls</extension>
<mime-type>text/vnd.wap.wmlscript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>dms</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>tr</extension>
<mime-type>application/x-troff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>texinfo</extension>
<mime-type>application/x-texinfo</mime-type>
</mime-mapping>
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>nc</extension>
<mime-type>application/x-netcdf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>wmlc</extension>
<mime-type>application/vnd.wap.wmlc</mime-type>
</mime-mapping>
<mime-mapping>
<extension>au</extension>
<mime-type>audio/basic</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gz</extension>
<mime-type>application/x-gzip</mime-type>
</mime-mapping>
<mime-mapping>
<extension>tiff</extension>
<mime-type>image/tiff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>rpm</extension>
<mime-type>audio/x-pn-realaudio-plugin</mime-type>
</mime-mapping>
<mime-mapping>
<extension>csh</extension>
<mime-type>application/x-csh</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ppt</extension>
<mime-type>application/powerpoint</mime-type>
</mime-mapping>
<mime-mapping>
<extension>vcd</extension>
<mime-type>application/x-cdlink</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ai</extension>
<mime-type>application/postscript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ms</extension>
<mime-type>application/x-troff-ms</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gtar</extension>
<mime-type>application/x-gtar</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pdf</extension>
<mime-type>application/pdf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>tcl</extension>
<mime-type>application/x-tcl</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ppm</extension>
<mime-type>image/x-portable-pixmap</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pdb</extension>
<mime-type>chemical/x-pdb</mime-type>
</mime-mapping>
<mime-mapping>
<extension>sit</extension>
<mime-type>application/x-stuffit</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xbm</extension>
<mime-type>image/x-xbitmap</mime-type>
</mime-mapping>
<mime-mapping>
<extension>wbmp</extension>
<mime-type>image/vnd.wap.wbmp</mime-type>
</mime-mapping>
<mime-mapping>
<extension>hqx</extension>
<mime-type>application/mac-binhex40</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ief</extension>
<mime-type>image/ief</mime-type>
</mime-mapping>
<mime-mapping>
<extension>oda</extension>
<mime-type>application/oda</mime-type>
</mime-mapping>
<mime-mapping>
<extension>tif</extension>
<mime-type>image/tiff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>me</extension>
<mime-type>application/x-troff-me</mime-type>
</mime-mapping>
<mime-mapping>
<extension>dxr</extension>
<mime-type>application/x-director</mime-type>
</mime-mapping>
<mime-mapping>
<extension>sh</extension>
<mime-type>application/x-sh</mime-type>
</mime-mapping>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>exe</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>texi</extension>
<mime-type>application/x-texinfo</mime-type>
</mime-mapping>
<mime-mapping>
<extension>wmlsc</extension>
<mime-type>application/vnd.wap.wmlscriptc</mime-type>
</mime-mapping>
<mime-mapping>
<extension>class</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>mpg</extension>
<mime-type>video/mpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>mpe</extension>
<mime-type>video/mpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>wav</extension>
<mime-type>audio/x-wav</mime-type>
</mime-mapping>
<mime-mapping>
<extension>sty</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>sv4crc</extension>
<mime-type>application/x-sv4crc</mime-type>
</mime-mapping>
<mime-mapping>
<extension>mov</extension>
<mime-type>video/quicktime</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xyz</extension>
<mime-type>chemical/x-pdb</mime-type>
</mime-mapping>
<mime-mapping>
<extension>rtx</extension>
<mime-type>text/richtext</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpe</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>hdf</extension>
<mime-type>application/x-hdf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ustar</extension>
<mime-type>application/x-ustar</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xml</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>bcpio</extension>
<mime-type>application/x-bcpio</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ra</extension>
<mime-type>audio/x-realaudio</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xsl</extension>
<mime-type>text/xsl</mime-type>
</mime-mapping>
<mime-mapping>
<extension>mif</extension>
<mime-type>application/x-mif</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
</orion-web-app>
Configuring the OC4J JSP Environment
Saturday, April 24, 2010
Friday, April 23, 2010
การ Pack .jar File
Command Prompt นะครับ
E:\ Servlet\WebContent\WEB-INF\classes>jar -cf y.jar com\*
//คือเอาตั้งแต่ com แล้วก็ sub directory ทุกตัวที่อยู่ใต้ com
หรือ
E:\ Servlet\WebContent\WEB-INF\classes>jar -cf y.jar *
//เอาทุกอย่าง pack เป็น jar ที่อยู่ใต้ classes
จากนั้น copy ไปไว้ที่ WEB-INF\lib
แล้วทำการ ลบข้อมูล .class ทุกอย่าง ออกไปให้หมด
เราก็สามารถใช้ class ได้จาก jar ของเราแล้ว
การปรับ Config server.xml ตอน Deploy
1.สิ่งที่ ควร comment
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
2.ควรทำการชี้ app ของเราไปที่อื่น เพื่อป้องกัน Secure
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="c:/myapp"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
ระวัง ก่อนการทำ ควร Backup File ไว้ด้วยทุกครั้ง
การ Run Tomcat แก้ไข Classpath.bat
C:\apache-tomcat-6.0.16\bin\ setclasspath.bat
rem Set standard command for invoking Java.
rem Note that NT requires a window name argument when using start.
rem Also note the quoting as JAVA_HOME may contain spaces.
set _RUNJAVA="%JRE_HOME%\bin\java" –server
หรือ
set _RUNJAVA="%JRE_HOME%\bin\java" –client นี่คือ default
set _RUNJAVAW="%JRE_HOME%\bin\javaw"
set _RUNJDB="%JAVA_HOME%\bin\jdb"
set _RUNJAVAC="%JAVA_HOME%\bin\javac"
java -help
C:\java -help
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
Tip Tomcat 1.6
ทดสอบแก้ไฟล์แล้ว รัน start เราจะไม่สามารถรัน command prompt ไม่ได้
C:\apache-tomcat-6.0.16\conf\server.xml
C:\apache-tomcat-6.0.16\bin
พิมพ์ startup
วิธีแก้ คือ
C:\apache-tomcat-6.0.16\bin
พิมพ์ catalina run
Thursday, April 22, 2010
การใช้ StringTokenizer
// Token.java
// StringTokenizer เป็น immutable
import java.io.*;
import java.util.*;
class Token {
public static void main(String args[]) throws IOException {
String s = "john jack:joe,jim;judy";
// StringTokenizer st = new StringTokenizer(s);
StringTokenizer st = new StringTokenizer(s, ",.;: ");
while(st.hasMoreElements())
System.out.println(st.nextToken());
}
}
เอาไว้ จัดการข้อมูลที่ส่งไป ส่งมาได้
String กับ StringBuffer ต่างกันในเรื่องของการเปลือง Memory บน Heap (Heap Memory)
// StringBufferTest1.java
class StringBufferTest1 {
public static void main(String args[]) {
String s = "";
// StringBuffer sb = new StringBuffer();
Runtime rt = Runtime.getRuntime();
long x = rt.freeMemory();
for(int i = 0; i < 1000; i++)
s += "0";
// sb.append("0");
long y = rt.freeMemory();
System.out.println(x - y);
}
}
// StringBufferTest2.java
class StringBufferTest2 {
public static void main(String args[]) {
//String s = "";
StringBuffer sb = new StringBuffer();
Runtime rt = Runtime.getRuntime();
long x = rt.freeMemory();
for(int i = 0; i < 1000; i++)
//s += "0";
sb.append("0");
long y = rt.freeMemory();
System.out.println(x - y);
}
}
//แนะนำควรใช้ ตัวที่เป็น StringBuffer เพราะไม่เปลือง Memory
String Immutable in Java
String a = new String("hello");
String b = new String("hello");
// a==b is false
String x="hello";
String y="hello";
//x==y is true
X==y นั้น
จาก y จะไปมองว่ามี hello หรือ ไม่ถ้ามี ก็จะ refer เลยทำให้ เท่ากับ true
การใช้งาน StringStream
// StringStream.java
import java.io.*;
class StringStream {
public static void main(String args[]) throws IOException {
String s = "Hello! how do you do?";
StringReader sr = new StringReader(s);
StringWriter sw = new StringWriter();
int c;
while ((c = sr.read()) != -1)
sw.write(c);
sr.close();
sw.close();
System.out.println(sw.toString());
}
}
javap java.io.File
C:\tmp\stream>javap java.io.File >io_file.txt
Compiled from "File.java"
public class java.io.File extends java.lang.Object implements java.io.Serializable,java.lang.Comparable{
public static final char separatorChar;
public static final java.lang.String separator;
public static final char pathSeparatorChar;
public static final java.lang.String pathSeparator;
static final boolean $assertionsDisabled;
int getPrefixLength();
public java.io.File(java.lang.String);
public java.io.File(java.lang.String, java.lang.String);
public java.io.File(java.io.File, java.lang.String);
public java.io.File(java.net.URI);
public java.lang.String getName();
public java.lang.String getParent();
public java.io.File getParentFile();
public java.lang.String getPath();
public boolean isAbsolute();
public java.lang.String getAbsolutePath();
public java.io.File getAbsoluteFile();
public java.lang.String getCanonicalPath() throws java.io.IOException;
public java.io.File getCanonicalFile() throws java.io.IOException;
public java.net.URL toURL() throws java.net.MalformedURLException;
public java.net.URI toURI();
public boolean canRead();
public boolean canWrite();
public boolean exists();
public boolean isDirectory();
public boolean isFile();
public boolean isHidden();
public long lastModified();
public long length();
public boolean createNewFile() throws java.io.IOException;
public boolean delete();
public void deleteOnExit();
public java.lang.String[] list();
public java.lang.String[] list(java.io.FilenameFilter);
public java.io.File[] listFiles();
public java.io.File[] listFiles(java.io.FilenameFilter);
public java.io.File[] listFiles(java.io.FileFilter);
public boolean mkdir();
public boolean mkdirs();
public boolean renameTo(java.io.File);
public boolean setLastModified(long);
public boolean setReadOnly();
public boolean setWritable(boolean, boolean);
public boolean setWritable(boolean);
public boolean setReadable(boolean, boolean);
public boolean setReadable(boolean);
public boolean setExecutable(boolean, boolean);
public boolean setExecutable(boolean);
public boolean canExecute();
public static java.io.File[] listRoots();
public long getTotalSpace();
public long getFreeSpace();
public long getUsableSpace();
public static java.io.File createTempFile(java.lang.String, java.lang.String, java.io.File) throws java.io.IOException;
public static java.io.File createTempFile(java.lang.String, java.lang.String) throws java.io.IOException;
public int compareTo(java.io.File);
public boolean equals(java.lang.Object);
public int hashCode();
public java.lang.String toString();
public int compareTo(java.lang.Object);
static java.io.FileSystem access$000();
static {};
}
ต้องการ write ลง file อย่าง ง่ายๆ
// PrintFile.java
import java.io.*;
class PrintFile {
public static void main(String args[]) {
PrintWriter pw = null;
try {
pw = new PrintWriter("tmp");
} catch(FileNotFoundException e) {
System.err.println(e);
}
pw.println("Hello! how do you do?");
pw.close();
}
}
DataRead ใช้ได้กับ Byte เท่านั้น
// DataRead.java
import java.io.*;
class DataRead {
public static void main(String args[]) throws IOException {
DataInputStream dis = new DataInputStream(System.in);
int x = dis.readInt();
double y = dis.readDouble();
System.out.println(x);
System.out.println(y);
}
}
ไว้ใช้กับตัวเลข เช่น ระบบ ธนาคาร
DataWrite ใช้ได้กับ Byte เท่านั้น
// DataWrite.java
import java.io.*;
class DataWrite {
public static void main(String args[]) throws IOException {
DataOutputStream dos = new DataOutputStream(System.out);
int x = 12345;
double y = 1.2345;
dos.writeInt(x);
dos.writeDouble(y);
dos.close();
}
}
เอา BufferedRW มาใช้งาน
// BufferedRW.java ใช้แบบนี้ ดี
import java.io.*;
class BufferedRW {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String s;
while ((s = br.readLine()) != null)
bw.write(s + "\n");
bw.close();
}
}
ทดสอบการใช้ Char Stream
// ThaiWrite.java
import java.io.*;
class ThaiWrite {
public static void main(String args[]) throws IOException {
// OutputStreamWriter osw = new OutputStreamWriter(System.out,"Cp1252");
OutputStreamWriter osw = new OutputStreamWriter(System.out, "MS874");
osw.write('\u0E01'); osw.write('ก');
osw.close();
}
}
Out ที่ได้คือ
กก
การทดสอบ Encoding Stream
// EncodingTest.java
import java.io.*;
class EncodingTest {
public static void main(String args[]) {
InputStreamReader isr = new InputStreamReader(System.in);
System.out.println(isr.getEncoding());
}
}
ค่าที่อ่านออกมาได้ จะเป็นรหัสของ Stream นั้นๆ (ตาม Localhost)
เช่น
ไทย MS874
อังกฤษ Cp1252
Stream Read,Write StreamRW.java
// StreamRW.java
import java.io.*;
class StreamRW {
public static void main(String args[]) throws IOException {
int n;
char [] b = new char [1024];
InputStreamReader isr = new InputStreamReader(System.in);
OutputStreamWriter osw = new OutputStreamWriter(System.out);
while ((n = isr.read(b)) > 0)
osw.write(b, 0, n);
osw.close();
}
}
//########################################################
การอ่าน Stream ต่อกัน ดูได้จาก System.in ß
เป็น Stream เหมือนกัน จากนั้นก็เอา InputStreamReader มารับ
นี่ก็คือ ที่เราเรียกว่า Stream ต่อ Stream
คำสั่ง เขียน method ของ class ไปเก็บไว้ที่ File
ที่ Command Prompt
C:\tmp>javap java.io.InputStream >is.txt
####################################################################
Output: c:\tmp\is.txt
####################################################################
Compiled from "InputStream.java"
public abstract class java.io.InputStream extends java.lang.Object implements java.io.Closeable{
public java.io.InputStream();
public abstract int read() throws java.io.IOException;
public int read(byte[]) throws java.io.IOException;
public int read(byte[], int, int) throws java.io.IOException;
public long skip(long) throws java.io.IOException;
public int available() throws java.io.IOException;
public void close() throws java.io.IOException;
public synchronized void mark(int);
public synchronized void reset() throws java.io.IOException;
public boolean markSupported();
}
Wednesday, April 21, 2010
Monday, April 19, 2010
Clear Memory In Java Lang
public
static
void main(String[] args) {
Runtime rt = Runtime.getRuntime();
System.out.println("1 ## "+rt.freeMemory());
A a[] = new A[1000];
for(int i=0;i<1000;i++){
a[i]=new A();
}
System.out.println("2 ## "+rt.freeMemory());
for(int i=0;i<1000;i++){
a[i]=null;
}
System.out.println("3 set null ## "+rt.freeMemory());
System.out.println("#################################");
rt.gc();
System.out.println("4 call .gc ## "+rt.freeMemory());
}
//######################### Out Put #############################
1 ## 4917112
2 ## 4894568
3 set null ## 4894568
#################################
4 call .gc ## 5013408