來處理編碼
但是當使用Get方法時,Tomcat沒有用正確的編碼來處理querystring,資料就會變成亂碼。
解決方法是修改tomcat資料夾下的
server.xml檔案,找到Connector標籤,加入URIEncoding="UTF-8"即可。
Ex:
<Connector port="8080" protocol="HTTP/1.1"
URIEncoding="UTF-8"
connectionTimeout="30000"
redirectPort="8443" />
<Connector port="8080" protocol="HTTP/1.1"
URIEncoding="UTF-8"
connectionTimeout="30000"
redirectPort="8443" />
| 快速鍵 | 效果 |
| CTRL + G | 移動到指定行號位置 |
| CTRL + F4 | 關閉程式頁籤 |
| CTRL + F | 尋找 |
| CTRL + SHIFT + F | 在檔案中尋找 |
| CTRL + H | 取代 |
| CTRL + SHIFT + H | 在檔案中取代 |
| CTRL + ALT + L | 檢視方案總管 |
| CTRL + ALT + X | 檢視工具列 |
| F5 | 開始偵錯 |
| CTRL + F5 | 啟動但不偵錯 |
| CTRL + SHIFT + W | 在瀏覽器中顯示 |
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Website</display-name> <servlet> <servlet-name>Website</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Website</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file> </welcome-file-list> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <aop:aspectj-autoproxy /> <context:component-scan base-package="website" /> <!-- viewResolver setup --> <context:component-scan base-package="website.controller" /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
@RequestMapping("/test.do")
public ModelAndView test(HttpServletRequest req,
HttpServletResponse resp) throws Exception {
return new ModelAndView("demo");
}
public String arrayToString(String[] input){ StringBuffer result = new StringBuffer(); if(input!=null){ boolean isFirstElement = true; for(int i = 0; i<input.length; i++){ if(isFirstElement){ result.append(input[i]); } else { result.append(", "); result.append(input[i]); } } } return result.toString(); }
public String arrayToString(String[] input){ StringBuffer result = new StringBuffer(); if(input!=null && input.length>0){ result.append(input[0]); for(int i = 1; i<input.length; i++){ result.append(", "); result.append(input[i]); } } return result.toString(); }
if(username!=null){ if(password!=null){ System.out.println("do something"); //這邊是要處理的邏輯 }else { System.out.println("password is null"); } }else { System.out.println("username is null"); }
if(username!=null && password!=null){ System.out.println("do something"); //這邊是要處理的邏輯 }else if(password==null){ System.out.println("password is null"); }else{ System.out.println("username is null"); }
import java.util.Date;
public class SumTest {
public static void main(String[] args) {
useForLoop(10000000);
useGaussMethod(10000000);
}
public static void useForLoop(long input){
long result = 0;
long startTime = new Date().getTime();
for(long i = 1;i<=input;i++){
result = result + i;
}
System.out.println(result);
long endTime = new Date().getTime();
long totalTime = endTime-startTime;
System.out.println(totalTime);
}
public static void useGaussMethod(long input){
long startTime = new Date().getTime();
long result = input*(input+1)/2;
System.out.println(result);
long endTime = new Date().getTime();
long totalTime = endTime-startTime;
System.out.println(totalTime);
}
}
public class copyArrayDemo {
public static void main(String[] args) {
System.out.println("This is demo 1");
int[] arr1 = {1,2,3};
int[] arr2 = new int[arr1.length+1];
System.arraycopy(arr1, 0, arr2, 0, arr1.length);
arr2[arr1.length]= 4;
// arr2 == {1,2,3,4}
for(int item:arr2){
System.out.println(item);
}
System.out.println("This is demo 2");
String[] array1 = {"item1","item2","item3"};
String[] array2 = {"demo1","demo2","demo3"};
String[] sum = new String[array1.length+array2.length];
System.arraycopy(array1, 0, sum, 0, array1.length);
System.arraycopy(array2, 0, sum, array1.length, array2.length);
// sum =={"item1","item2","item3","demo1","demo2","demo3"}
for(String item:sum){
System.out.println(item);
}
}
}