arr=(aaa@example.com bbb@example.com ccc@example.com) for ((i=0; i<${#arr[@]}; i++)); do echo ${arr[$i]} done輸出
aaa@example.com
bbb@example.com
ccc@example.com
初學者注意空格.
arr=(aaa@example.com bbb@example.com ccc@example.com) for ((i=0; i<${#arr[@]}; i++)); do echo ${arr[$i]} done輸出
$CATALINA_HOME
. (Otherwise, read "How to install Tomcat".)struts-2.1.8.1-all.zip
".lib
", which includes 71 jar-files. To deploy Struts application in Tomcat, these libaries must be available to Tomcat. You could copy the selected jar-files into Tomccat's "lib
" directory (i.e., $CATALINA_HOME\lib
), which will be available to all the web applications. You could also place the jar-files into a specific web context's "lib
" directory, which will be available to only the particular web application.apps
", in the form of war-files. In particular, a "blank" application template for which you can use to start writing your own codes. War-file (Web Application Archive) uses ZIP algorithm to compress and group files. You can extract the contents of war-file using WINZIP, WINRAR, or any other ZIP programs.webapps
" directory ($CATALINA_HOME\webapps
). Let's copy the "blank" sample application struts2-blank-2.1.8.1.war
into Tomcat's "webapps
". Start your Tomcat. The war-file will be unzipped and deployed automatically. Observer the following message in the Tomcat's console:INFO: Deploying web application archive struts2-blank-2.1.8.1.war May 1, 2010 11:32:41 AM com.opensymphony.xwork2.util.logging.jdk.JdkLogger info INFO: Parsing configuration file [struts-default.xml] May 1, 2010 11:32:41 AM com.opensymphony.xwork2.util.logging.jdk.JdkLogger info INFO: Parsing configuration file [struts-plugin.xml] May 1, 2010 11:32:41 AM com.opensymphony.xwork2.util.logging.jdk.JdkLogger info INFO: Parsing configuration file [struts.xml]
webapps
":$CATALINA_HOME
\webapps\
struts2-blank-2.1.8.1
": This directory is known as context root of the web application "struts2-blank-2.1.8.1
", which keeps the "html
", "jsp
" files accessible by the users. In this example, the home page "index.html
".$CATALINA_HOME
\webapps\
struts2-blank-2.1.8.1
\WEB-INF
": This directory is hidden from user and keeps the configuration files. You keep the configuration file in this directory and program codes in its sub-directories. In this example, it contains a configuration file "web.xml
" for configuring this web application.$CATALINA_HOME
\webapps\
struts2-blank-2.1.8.1
\WEB-INF\src
": Keep the java program source files (optional).$CATALINA_HOME
\webapps\
struts2-blank-2.1.8.1
\WEB-INF\classes
": Keep the java classes.$CATALINA_HOME
\webapps\
struts2-blank-2.1.8.1
\WEB-INF\lib
": keep the runtime libraries (jar-files) for this application.$CATALINA_HOME
\webapps\
struts2-blank-2.1.8.1
\META-INF
":May 1, 2010 4:18:56 PM org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive struts2-blank-2.1.8.1.war May 1, 2010 4:18:56 PM com.opensymphony.xwork2.util.logging.jdk.JdkLogger info INFO: Parsing configuration file [struts-default.xml] May 1, 2010 4:18:57 PM com.opensymphony.xwork2.util.logging.jdk.JdkLogger info INFO: Parsing configuration file [struts-plugin.xml] May 1, 2010 4:18:57 PM com.opensymphony.xwork2.util.logging.jdk.JdkLogger info INFO: Parsing configuration file [struts.xml]To access the sample struts application, issue URL
http://loaclhost:8080/struts2-blank-2.1.8.1
from a web browser. The home page "index.html
" redirect to "example\Helloworld.jsp
". Browse thru the source code of these pages.http://loaclhost:8080/struts2-blank-2.1.8.1/example/Welcome.jsp
, and browse thru the source codes for these pages in "example
" sub-directory.hellostruts2
" in Tomcat for our Struts Hello-world application, by creating the standard directory structure for the web context (as shown in the figure below). Create a directory called "hellostruts2
", under the Tomcat's webapps
directory ($CATALINA_HOME\webapps
). Create a sub-directory "WEB-INF
" under "hellostruts2
". Create sub-directories: "classes
", "lib
" and "src
" under "WEB-INF
". Take note that the directory names are case-sensitive.lib
": commons-fileupload-1.2.1.jar
, commons-io-1.3.2.jar
, freemarker-2.3.15.jar
, ognl-2.7.3.jar
, struts2-core-2.1.8.1.jar
, xwork-core-2.1.6.jar
.web.xml
". Save in "$CATALINA_HOME\webapps\hellostruts2\WEB-INF
". The <filter>
tag sets up the struts's dispatcher. The <filter-mapping>
maps URL pattern "/*
" (all requests under the root) to struts.<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>Create the following configuration file for struts "
struts.xml
". Save in "$CATALINA_HOME\webapps\hellostruts2\WEB-INF\classes
". An action called HelloWorld
is declared, which is mapped to hello.HelloWorld
class. If the action returns a string "Success
", invoke "/response.jsp
".<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" extends="struts-default"> <action name="HelloWorld" class="hello.HelloWorld"> <result name="Success">/response.jsp</result> </action> </package> </struts>
input.jsp
": save under the context root "$CATALINA_HOME\webapps\hellostruts2
". This page is used to produce the following form:<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="/struts-tags" prefix="s" %> <html> <head> <title>Hello World</title> </head> <body> <h1>User Input Form</h1> <s:form action="HelloWorld" > <s:textfield name="name" label="Enter Your Name: " /> <s:submit value="Send" /> </s:form> </body> </html>
's'
.<s:form>
defines a HTML form, with processing action of "HelloWorld
". The "HelloWorld
" action is mapped to "hello.HelloWorld
" class (in "struts.xml
").<s:textfield>
define a text field element. The value will be captured in a field "name
" of the "hello.HelloWorld
" class.hello.HelloWorld
": save as "hellostruts2\WEB-INF\src\hello\HelloWorld.java
"package hello; public class HelloWorld { private String message; private String name; public String execute() { setMessage("Hello, " + getName()); return "Success"; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
hellostruts2\WEB-INF
", and use -d
option to set the output directory: > javac -d classes src\hello\HelloWorld.java
execute()
method, which returns a string. From "struts.xml
", if the return result is "Success
", forward to "\response.jsp
".name
and message
, are defined together with the public getters and setters.response.jsp
": saved as "hellostruts2\response.jsp
". This page accesses the "message
" property of the class "hello.HelloWorld
", and has a "Back" button to return to "/input.jsp
".<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="/struts-tags" prefix="s" %> <html> <head> <title>Response Page</title> </head> <body> <h1><s:property value="message" /></h1> <s:form action="/input.jsp" > <s:submit value="Back" /> </s:form> </body> </html>
hellostruts2
" has been started.May 1, 2010 4:18:59 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory hellostruts2 May 1, 2010 4:18:59 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info INFO: Parsing configuration file [struts-default.xml] May 1, 2010 4:18:59 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info INFO: Parsing configuration file [struts-plugin.xml] May 1, 2010 4:18:59 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info INFO: Parsing configuration file [struts.xml]
http://localhost:8080/hellostruts2/input.jsp
input.jsp
" and "response.jsp
".
class SqrtDemo { public static void main(String[] args) { System.out.println(Math.max(35, 48)); System.out.println(Math.max(22.3, 22.1)); System.out.println(Math.max(0.00365f, 0.00365002f)); System.out.println(Math.max(652l, 965l)); } }
48 22.3 0.00365002 965Math 類別有 static min() 方法 (method) ,回傳兩個參數 (parameter) 中的較小值
class SqrtDemo { public static void main(String[] args) { int i; for (i = 0; i <= 10; i++) { System.out.println(Math.sqrt(i)); } } }
0.0 1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979 2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795
//UnZip.java package com.hl; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class UnZip { private boolean staus=false; public UnZip(String file){ String unzipfile = file; //解壓縮的檔案名包含路徑 try { File olddirec = new File(unzipfile); //解壓縮的檔路徑(為了獲取路徑) ZipInputStream zin = new ZipInputStream(new FileInputStream(unzipfile)); ZipEntry entry; //創建文件夾 while ( (entry = zin.getNextEntry()) != null){ if (entry.isDirectory()) { File directory = new File(olddirec.getParent(), entry.getName()); if (!directory.exists()) if (!directory.mkdirs()) System.exit(0); zin.closeEntry(); } if (!entry.isDirectory()) { File myFile = new File(entry.getName()); //輸出路徑 String ofile=file.replace(".zip", ""); File fo=new File(ofile); if(!fo.exists()){ fo.mkdir(); } FileOutputStream fout = new FileOutputStream(ofile+"/"+myFile.getPath()); DataOutputStream dout = new DataOutputStream(fout); byte[] b = new byte[1024]; int len = 0; while ( (len = zin.read(b)) != -1) { dout.write(b, 0, len); } dout.close(); fout.close(); zin.closeEntry(); staus=true; } } } catch (IOException e) { e.printStackTrace(); } } public boolean getStaus(){ return staus; } }
<?php
$zip = zip_open("test.zip");
zip_read($zip);
// some code .....
zip_close($zip);
?>
<%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <H1>Adobe FDF Example</H1> <FORM NAME=W4Help ACTION=W4.asp METHOD = POST> <TABLE> <TR> <TD ALIGN=RIGHT VALIGN=TOP>First Name</TD> <TD><INPUT TYPE=TEXT NAME=txtFirstName> </TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>Middle Initial </TD> <TD><INPUT TYPE=TEXT NAME=txtMI> </TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>LastName</TD> <TD><INPUT TYPE=TEXT NAME=txtLastName> </TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>Social</TD> <TD><INPUT TYPE=TEXT NAME=txtSocial1 SIZE=3>- <INPUT TYPE=TEXT NAME=txtSocial2 SIZE=2>- <INPUT TYPE=TEXT NAME=txtSocial3 SIZE=2></TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>Street Address</TD> <TD><INPUT TYPE=TEXT NAME=txtStreetAddress></TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>City </TD> <TD><INPUT TYPE=TEXT NAME=txtCity></TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>State</TD> <TD><INPUT TYPE=TEXT NAME=txtState SIZE=2 MAXLENGTH=2></TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>Zip</TD> <TD><INPUT TYPE=TEXT NAME=txtZip SIZE=10></TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>Filing Status</TD> <TD> <INPUT TYPE=RADIO NAME=radFilingStatus VALUE="1">Single <BR> <INPUT TYPE=RADIO NAME=radFilingStatus VALUE="2">Married <BR> <INPUT TYPE=RADIO NAME=radFilingStatus VALUE="3"> Married but withholding at the higher single rate. <BR></TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>Allowances Claimed</TD> <TD><INPUT TYPE=TEXT NAME=txtAllowances SIZE=2 MAXLENGTH=2> </TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>Additional amount to withhold (if any)</TD> <TD><INPUT TYPE=TEXT NAME=txtAdditional SIZE=2 MAXLENGTH=2> </TD> </TR> <TR> <TD ALIGN=RIGHT VALIGN=TOP>I want to file Exempt from Withholding </TD> <TD><INPUT TYPE=CHECKBOX NAME=chkExempt></TD> </TR> </TABLE> <INPUT TYPE=SUBMIT> </FORM> </BODY> </HTML>Step 4. Define the Adobe form fields.
<%@ Language=VBScript %>
<% Response.Buffer = true%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<%
'
' Retrieve the user responses
'
FirstName = Request.form("txtFirstName")
MI = Request.form("txtMI")
LastName = Request.form("txtLastName")
SS1 = Request.form("txtSocial1")
SS2 = Request.form("txtSocial2")
SS3 = Request.form("txtSocial3")
StreetAddress = Request.form("txtStreetAddress")
City = Request.form("txtCity")
State = Request.form("txtState")
Zip = Request.form("txtZip")
FilingStatus = Request.form("radFilingStatus")
Allowances = Request.form("txtAllowances")
Additional = Request.form("txtAdditional")
Exempt = Request.form("chkExempt")
If Exempt = "on" Then
Exempt = "EXEMPT"
Else
Exempt = ""
End If
'
' Create an instance of the Object
'
Set FdfAcx = Server.CreateObject("FdfApp.FdfApp")
'
' Use the fdfApp to feed the vars
'
Set myFdf = FdfAcx.FDFCreate
'
' Stuff the variables
'
myFdf.fdfsetvalue "FirstName", FirstName, false
myFdf.fdfsetvalue "MI", MI, false
myFdf.fdfsetvalue "LastName", LastName, false
myFdf.fdfsetvalue "SS1", SS1, false
myFdf.fdfsetvalue "SS2", SS2, false
myFdf.fdfsetvalue "SS3", SS3, false
myFdf.fdfsetvalue "StreetAddress", StreetAddress, false
myFdf.fdfsetvalue "City", City, false
myFdf.fdfsetvalue "State", State, false
myFdf.fdfsetvalue "Zip", Zip, false
If FilingStatus = 1 Then
MyFdf.fdfsetValue "StatusSingle", "X", false
End If
If FilingStatus = 2 Then
MyFdf.fdfsetValue "StatusMarried", "X", false
End If
If FilingStatus = 3 Then
MyFdf.fdfsetValue "MarriedBut", "X", false
End If
myFdf.fdfsetvalue "Allowances", Allowances, false
myFdf.fdfsetvalue "Additional", Additional, false
myFdf.fdfsetvalue "Exempt", Exempt, false
'
' Point to your pdf file
'
myFDF.fdfSetFile "http://www.servername.com/workorder/w4.pdf"
Response.ContentType = "text/html"
'
' Save it to a file. If you were going to save the actual file past the point of printing
' You would want to create a naming convention (perhaps using social in the name)
' Have to use the physical path so you may need to incorporate Server.mapPath in
' on this portion.
'
myFDf.FDFSaveToFile "C:\inetpub\wwwroot\workorder\CheckThis.fdf"
' Now put a link to the file on your page.
Response.Write "<a href=http://www.servername.com/workorder/CheckThis.fdf>pdf</A>"
'
' Close your Objects
'
myfdf.fdfclose
set fdfacx = nothing
%>
class GCM { //put your code here // constructor function __construct() { } /** * Sending Push Notification */ public function send_notification($registatoin_ids, $message) { // include config include_once './config.php'; // Set POST variables $url = 'https://android.googleapis.com/gcm/send'; $fields = array( 'registration_ids' => $registatoin_ids, 'data' => $message, ); $headers = array( 'Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json' ); // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Disabling SSL Certificate support temporarly curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); // Execute post $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } // Close connection curl_close($ch); echo $result; } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </LinearLayout>另外使用一個 ImageView 用來顯示被選取的 Gallery 照片。 還有一個位於 res/values/attrs.xml 的 XML 設定檔:
// Declare the class class GoogleUrlApi { // Constructor function GoogleURLAPI($key,$apiURL = 'https://www.googleapis.com/urlshortener/v1/url') { // Keep the API Url $this->apiURL = $apiURL.'?key='.$key; } // Shorten a URL function shorten($url) { // Send information along $response = $this->send($url); // Return the result return isset($response['id']) ? $response['id'] : false; } // Expand a URL function expand($url) { // Send information along $response = $this->send($url,false); // Return the result return isset($response['longUrl']) ? $response['longUrl'] : false; } // Send information to Google function send($url,$shorten = true) { // Create cURL $ch = curl_init(); // If we're shortening a URL... if($shorten) { curl_setopt($ch,CURLOPT_URL,$this->apiURL); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode(array("longUrl"=>$url))); curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-Type: application/json")); } else { curl_setopt($ch,CURLOPT_URL,$this->apiURL.'&shortUrl='.$url); } curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // Execute the post $result = curl_exec($ch); // Close the connection curl_close($ch); // Return the result return json_decode($result,true); } }
// Create instance with key $key = 'xhjkhzkhfuh38934hfsdajkjaf'; $googer = new GoogleURLAPI($key); // Test: Shorten a URL $shortDWName = $googer->shorten("http://davidwalsh.name"); echo $shortDWName; // returns http://goo.gl/i002 // Test: Expand a URL $longDWName = $googer->expand($shortDWName); echo $longDWName; // returns http://davidwalsh.name
button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://2mecode.wordpress.com")); startActivity(intent); } });
private void RedFlashLight()
{
NotificationManager nm =
( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
Notification notif = new Notification();
notif.ledARGB = 0xFFff0000;
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.ledOnMS = 100;
notif.ledOffMS = 100;
nm.notify(LED_NOTIFICATION_ID, notif);
}