* Password with USA :
First match : Cameroon
10300 - Japan
30700 - France
01500 - Russia
22000 - Spain
72100 - England
11500 - Mexico
42400 - Holland
62600 - Brazil
60200 - Italy
22300 - Argentina
12800 - W. Germany (last match)
* Password with Holland :
First match - Cameroon
10301 - Japan
30701 - France
01501 - Russia
22001 - Spain
72101 - England
11501 - Mexico
42401 - USA
62601 - Brazil
60201 - Italy
22301 - Argentina
12801 - W. Germany (last match)
* Password with Japan :
First match - Cameroon
10302 - USA
30702 - France
01502 - Russia
22002 - Spain
72102 - England
11502 - Mexico
42402 - Holland
62602 - Brazil
60202 - Italy
22302 - Argentina
12802 - W. Germany (last match)
* Password with France :
First match - Cameroon
10303 - Japan
30703 - USA
01503 - Russia
22003 - Spain
72103 - England
11503 - Mexico
42403 - Holland
62603 - Brazil
60203 - Italy
22303 - Argentina
12803 - W. Germany (last match)
* Password with Cameroon :
First match - USA
10304 - Japan
30704 - France
01504 - Russia
22004 - Spain
72104 - England
11504 - Mexico
42404 - Holland
62604 - Brazil
60204 - Italy
22304 - Argentina
12804 - W. Germany (last match)
* Password with Russia :
First match - Cameroon
10305 - Japan
30705 - France
01505 - USA
22005 - Spain
72105 - England
11505 - Mexico
42405 - Holland
62605 - Brazil
60205 - Italy
22305 - Argentina
12805 - W. Germany (last match)
* Password with Mexico :
First match - Cameroon
10306 - Japan
30706 - France
01506 - Russia
22006 - Spain
72106 - England
11506 - USA
42406 - Holland
62606 - Brazil
60206 - Italy
22306 - Argentina
12806 - W. Germany (last match)
* Password with England :
First match - Cameroon
10307 - Japan
30707 - France
01507 - Russia
22007 - Spain
72107 - USA
11507 - Mexico
42407 - Holland
62607 - Brazil
60207 - Italy
22307 - Argentina
12807 - W. Germany (last match)
* Password with Spain :
First match - Cameroon
10308 - Japan
30708 - France
01508 - Russia
22008 - USA
72108 - England
11508 - Mexico
42408 - Holland
62608 - Brazil
60208 - Italy
22308 - Argentina
12808 - W. Germany (last match)
* Password with Brazil :
First match - Cameroon
10309 - Japan
30709 - France
01509 - Russia
22009 - Spain
72109 - England
11509 - Mexico
42409 - Holland
62609 - USA
60209 - Italy
22309 - Argentina
12809 - W. Germany (last match)
* Password with W. Germany :
First match - Cameroon
10310 - Japan
30710 - France
01510 - Russia
22010 - Spain
72110 - England
11510 - Mexico
42410 - USA
62610 - Holland
60210 - Brazil
22310 - Italy
12810 - Argentina (last match)
* Password with Argentina :
First match - Cameroon
10311 - Japan
30711 - France
01511 - Russia
22011 - Spain
72111 - England
11511 - Mexico
42411 - USA
62611 - Brazil
60211 - Holland
22311 - Italy
12811 - W. Germany (last match)
* Password with Italy :
First match - Cameroon
10312 - Japan
30712 - France
01512 - Russia
22012 - Spain
72112 - England
11512 - Mexico
42412 - Holland
62612 - Brazil
60212 - USA
22312 - Argentina
12812 - W. Germany (last match)
<html:link> 標籤用於生成HTML <a> 元素。<html:link> 在創建超鏈接時,有兩個優點: <html:link> 標籤有以下重要屬性: <html:rewrite> 用於輸出超鏈接中的URI部分,但它並不生成HTML <a> 元素。URI指的是URL 中協議、主機和端口以後的內容。URI 用於指定具體的請求資源。例如,對於URL:HTTP://localhost:8080/HtmlBasic.do,它的URI為/HtmlBasic.do 示例: 2、創建具有完整URL 的鏈接 3、從當前網頁中創建相對URL 4、在URL 或 URI 中包含請求參數 提示:在HTML 中& 代表特殊字符 “&” 5、在URL 或 URI 中包含單個請求變量 rewrite: <html:rewrite page=”/HtmlBasic.do” <html:link> 標籤的 paramId 屬性指定請求參數名,paramName 屬性指定變量的名字。如果變量為JavaBean ,用paramProperty 屬性指定JavaBean 的屬性。 <a href=”/HtmlBasic.do?urlParamName=weiqin”> rewrite: /HtmlBasic.do?urlParamName=Value to Pass on Url <html:link> 標籤的name 屬性指定包含請求變量的HashMap 對象。HashMap 對象中的每一對”key/value” 代表一對或多對”請求參數名/請求參數值”。以上代碼生成如下的Html 內容:
(1) 允許在URL 中以多種方式包含請求參數。
(2) 當用戶瀏覽器關閉Cookie 時,會自動重寫URL,把SessionID 作為請求參數包含在URL 中,用於跟蹤用戶的Session 狀態。
(1) forward:指定全局轉發鏈接。
(2) href:指定完整的URL 鍵接。
(3) page:指定相對於當前網頁的URL。
1、創建全局轉發鏈接
首先,在Struts-config.xml 中<global-forwards> 元素中定義一個<forward> 元素:
<global-forwards>
<forward name = “index” path=”/index.jsp”/>
</global-forwards>
接著,在JSP 文件中創建<html:link> 標籤:
<html:link forward=”index”>
Link to Global ActionForward
</html:link>
<html:link> 標籤的forward 屬性和<global-forwards> 元素中的<forward> 子元素匹配。以上代碼生成如下HTML 內容:
<a href=”/index.jsp”>Link to Global ActionFoward</a>
值得注意的是,<html:link> 的forward 屬性只引用Struts-config.xml 配置文件中<global-forwards>內的<forward> 子元素,如果引用<action> 內的<forward> 子元素,在運行時將會拋出異常:
Cannot create rewrite URL: Java.Net.MalfomedURlException: Cannot retrieve ActionForward
如果Web 應用需要鏈接到其他站點,應該給出其他站點完整URL,例如:
<html:link href=”http://jakarta.apache.org/struts/index.html“>
Generate an “href” directly
</html:link>
生成HTML 代碼如下:
<a href=”http://jakarta.apache.org/struts/index.html“>Generate an “href” directly</a>
值得注意的是,如果指定了<html:link> 標籤的href 屬性,即使用戶瀏覽器的Cookie 關閉,<html:link> 標籤也不會把用戶SessionID 作為請求參數加和到URL 中。
如果從一個網頁鏈接到同一個應用中的另一網頁,可以採用以下方式:
<html:link page=”/HtmlBasic.do”>
A relative link from this page
</html:link>
<html:link> 標籤的 page 屬性用於指定相對於當前應用的URI。以上代碼生成如下HTML 內容:
<a href=”/lib/HtmlBasic.do”>……</a>
如果要在URL或URI 中包含請求參數,只要把請求參數加在URL 或 URI的末尾就可以了。例如:
<html:link page=”/HtmlBasic.do?prop1=abc&prop2=123”>
Hard-code the url parameters
</html:link>
<!— or —>
<html:rewrite page=”/HtmlBasic.do?prop1=abc&prop2=123”/>
以上代碼生成如下HTML 內容:
<a href=/lib/HtmlBasic.do?prop1=abc&prop2=123”>……</a>
rewrite: /HtmlBasic.do?prop1=abc&prop2=123
如果要在URL 中包含一個請求參數,而這人參數的值存在於當前網頁可訪問的一個變量中,可以按以下方法來實現。
為了演示這一功能,首先創建一個當前網頁可訪問的變量。例如,本例中創建了兩個變量,一個是字符類型,一個是CustomerBean , 它們存存於一個 page 範圍內:
<%
/*
* Create a string object to store as a bean in
* the page content and embed in this link
*/
String stringBean = “Value to Pass ont URL”;
pageContext.setAttribute(“stringBean”, stringBean);
%>
<jsp:useBean id = “customerBean” scope=”page” class=”htmltaglibs.beans.CurstomerBean”/>
<jsp:setProperty name=”customerBean” property=”name” value=”weiqin”/>
接著,把這兩個變量作為請求參數,加入到URL或URI 中:
<html:link page=”/HtmlBasic.do”
paramId=”urlParamName”
paramName=”stringBean”>
URL encode a parameter based on a string bean value
</html:link>
<html:link page=”/HtmlBasic.do”
paramId=”urlParamName”
paramName=”customerBean”
paramProperty=”name”>
URL encode a parameter based on a customer bean value
</html:link>
paramId=”urlParamName” paramName=”stringBean”/>
rewrite: <html:rewrite page=”/HtmlBasic.do”
paramId=”urlParamName” paramName=”customerBean”
paramProperty=”name”/>
對於本例的stringBean,請求參數值為stringBean 的字符串值。對於customerBean,指定了paramProperty 屬性,請求參數值為customerBean 的 name 屬性值。
以上代碼生成如下HTML 內容:
<a href=”/HtmlBasic.do?urlParamName=Value to Pass on Url”>
Url encode a paramter based on a string bean value
</a>
url encode a parameter based on a customer bean value
</a>
rewrite: /HtmlBasic.do?urlParamName=weiqin
6、在URL 或 URI 中包含多個請求變量
如果在URL 或 URI 中包含多個請求參數,而這些參數的值來自多個變量,需要先定義一個Map類型的java 類,如java.util.HashMap,用它來存放請求變量。例如:
<%
/*
* Strore values int a Map(HashMap in this case)
* and construct the URL based on the Map
* /
java.util.HashMap myMap = new java.util.HashMap();
myMap.put(“myString”, new String(“myStringValue”));
myMap.put(“myArray” , new String[]{“str1”,”str2”,”str3”} );
pageContext.setAttribute(“map”, myMap);
%>
在以上代碼的HaspMap 中存放了兩個對象,其中第二個對象是個字符串數組。HashMap 被存放在PageContext 中。 接下來就可以把這個HashMap 作為請求參數,加入到URL 或 URI 中:
<%— For this version of the <html:link> tag: —%>
<%— map = a map with name/value pairs to pass on the url —%>
<html:link page=”/HtmlBasic.do” name=”map”>
URL encode a parameter based on value in a Map
</html:link>
<%— Create the same rewrite string for the above link. —%>
rewrite:<html:rewrite page=”/HtmlBasic.do” name=”map”/>
<a href=”/HtmlBasic.do?myString=myStringValue&myArray=str1&myArray=str2&myArray=str3”>
URL encode a parameter based on value in a Map
</a>
rewrite:/HtmlBasic.do?myString=myStringValue&myArray=str1&myArray=str2&myArray=str3
EL 表達式的格式是這樣的:用美元符號($)定界,內容包括在花括號({})中,如清單 3 所示。
清單 3. 說明 EL 表達式定界符的 JSTL 操作
<c:out value=”${user.firstName}”/>
一、request.getParameter() 和request.getAttribute() 區別 (1)request.getParameter()取得是通過容器的實現來取得通過類似post,get等方式傳入的數據,request.setAttribute()和getAttribute()只是在web容器內部流轉,僅僅是請求處理階段。 (2)request.getParameter()方法傳遞的數據,會從Web客戶端傳到Web伺服器端,代表HTTP請求數據。request.getParameter()方法返回String類型的數據。 request.setAttribute()和getAttribute()方法傳遞的數據只會存在于Web容器內部 還有一點就是,HttpServletRequest類有setAttribute()方法,而沒有setParameter()方法。 拿一個例子來說一下吧,假如兩個WEB頁面間為鏈接關系時,就是說要從1.jsp鏈接到2.jsp時,被鏈接的是2.jsp可以通過getParameter()方法來獲得請求參數. 假如1.jsp里有 < % String username=request.getParameter(“username”); %> 但是如果兩個WEB間為轉發關系時,轉發目的WEB可以用getAttribute()方法來和轉發源WEB共享request范圍內的數據,也還是說一個例子吧。 有1.jsp和2.jsp 1.jsp希望向2.jsp傳遞當前的用戶名字,如何傳遞這一數據呢?先在1.jsp中調用如下setAttribute()方法: 在2.jsp中通過getAttribute()方法獲得用戶名字: request.getAttribute("nameOfObj")可得到JSP頁面一表單中控件的Value。其實表單控件中的Object的 name與value是存放在一個哈希表中的,所以在這里給出Object的name會到哈希表中找出對應它的value。 而不同頁面間傳值使用request.setAttribute(position, nameOfObj)時,只會從a.jsp到b.jsp一次傳遞,之后這個request就會失去它的作用范圍,再傳就要再設一個 request.setAttribute()。而使用session.setAttribute()會在一個過程中始終保有這個值。 P.S.:javascript與JSP中不能相互傳值,因為javascript運行在客戶端,而JSP運行在伺服器端。若想使它們之間可以相互傳遞參數,可以在JSP中設置一個hidden控件,用它的value結合上面所說的用法來傳遞所需的數值。
請輸入用戶姓名:
的話在2.jsp中通過request.getParameter("username")方法來獲得請求參數username:
<%
String username=request.getParameter("username");
request.setAttribute("username",username);
%>
<% String username=(String)request.getAttribute(“username”); %>
二、request.getAttribute()與request.setAttribute()
private static final String URL_UNRESERVED =
”ABCDEFGHIJKLMNOPQRSTUVWXYZ” +
”abcdefghijklmnopqrstuvwxyz” +
”0123456789-_.~”;
private static final char[] HEX = “0123456789ABCDEF”.toCharArray();
private static String urlEncode(String str) {
StringBuffer buf = new StringBuffer();
byte[] bytes = null;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeUTF(str);
bytes = bos.toByteArray();
} catch (IOException e) {
// ignore
}
for (int i = 2; i < bytes.length; i++) {
byte b = bytes[i];
if (URL_UNRESERVED.indexOf(b) >= 0) {
buf.append((char) b);
} else {
buf.append(‘%’).append(HEX[(b » 4) & 0x0f]).append(HEX[b & 0x0f]);
}
}
return buf.toString();
}
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4
at idv.jeltsine.shirobuncho.featureselection.ReliefF.getChosenIndexesOfPoint(ReliefF.java:89)
at idv.jeltsine.shirobuncho.featureselection.ReliefF.getWeight(ReliefF.java:26)
at idv.jeltsine.shirobuncho.featureselection.Ghiselli.getMerit(Ghiselli.java:12)
at idv.jeltsine.shirobuncho.test.cfsreliabilitytest.main(cfsreliabilitytest.java:47)