Category: Web 開發 Q&A

[Q&A]open unicode file in tomcat

add URIEncoding=”UTF-8″ in server.xml

1
2
3
4
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>
Tags :

[Q&A]mysql supports utf8mb4

my.cnf

1
2
3
4
5
6
7
8
9
10
11
[client] 
default-character-set = utf8mb4
 
[mysql] 
default-character-set = utf8mb4
 
[mysqld] 
character-set-client-handshake = FALSE 
character-set-server = utf8mb4 
collation-server = utf8mb4_unicode_ci 
init_connect='SET NAMES utf8mb4'

JDBC connector

remove characterEncoding=utf8

1
<property name="url" value="jdbc:mysql://localhost:3306/tomali?useUnicode=true&autoReconnect=true"/>
Tags : ,

[QA]How to set php upload_max_filesize in .htaccess?

php_value upload_max_filesize 10M

need enable AllowOverride in root

AllowOverride Options
Tags :

[問題] servlet 如何獲得 request URL

假設 Request Servlet URL 如下:

http://hostname.com/mywebapp/servlet/MyServlet/a/b;c=123?d=456

獲得 RequestURL 完整路徑:

/**
*
* @param req
* @return http://hostname.com/mywebapp/servlet/MyServlet/a/b;c=123?d=456
*/
public static String getRequestURL(HttpServletRequest req) {
   String reqUrl = req.getRequestURL().toString();
   String queryString = req.getQueryString(); // d=456
   if (queryString != null) {
      reqUrl += "?"+queryString;
   }
   return reqUrl;
}

獲得 Request URI:

/**
*
* @param req
* @return /mywebapp/servlet/MyServlet/a/b;c=123?d=456
*/
public static String getRequestURI(HttpServletRequest req) {
   String reqUri = req.getRequestURI().toString();
   String queryString = req.getQueryString(); // d=456
   if (queryString != null) {
      reqUri += "?"+queryString;
   }
   return reqUri;
}

獲得 Request Root URL:

/**
*
* @param req
* @return http://hostname.com/mywebapp
*/
public static String getRootURL(HttpServletRequest req) {
   String scheme = req.getScheme(); // http
   String serverName = req.getServerName(); // hostname.com
   int serverPort = req.getServerPort(); // 80
   String contextPath = req.getContextPath(); // /mywebapp
// String pathInfo = req.getPathInfo(); // /a/b;c=123
// String queryString = req.getQueryString(); // d=456
   String url = scheme+"://"+serverName+":"+serverPort+contextPath;
   return url;
}
Tags : ,

[QA] How to get the path of remote app in tomcat

HttpServletRequest

request.getSession().getServletContext().getRealPath("/");

Servlet

this.getServletContect().getRealPath("/");

Structs

this.getServlet().getServletContext().getRealPath("/");

ClassLoader

File classes = new File(getClass().getClassLoader().getResource("").getFile());
 
String path = classes.getParentFile().getParent() + "/";
 
path = java.net.URLDecoder.decode(path, "utf-8");
Tags :

[問題] mysql error 1025 (errorno: 150) 怎麼解決

alter table MY_TABLE drop foreign key my_table_ibfk_1;
alter table MY_TABLE drop column MY_COLUMN;
Tags :

[問題]如何在 MySQL 使得 SELECT case sensitive

使用 BINARY 關鍵字

SELECT * FROM my_table WHERE BINARY col_name = 'SoME wORd';
Tags :

[問題]如何在Tomcat安裝多個 webapp (不同domain name) 使用同一個ip

編輯 Server.xml,新增 <Host></Host>

<!-- Tomcat 預設 -->
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
<!-- 新增 www.mydomainname1.com -->
<Host name="www.mydomainname1.com"  appBase="mydomainname1"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>mydomainname1.com</Alias>
</Host>
!-- 新增 www.mydomainname2.com -->
<Host name="www.mydomainname2.com"  appBase="mydomainname2"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>mydomainname2.com</Alias>
</Host>

所存放的目錄結構如下

${TOMCAT_HOME}/webapps/ROOT
${TOMCAT_HOME}/mydomainname1/ROOT
${TOMCAT_HOME}/mydomainname2/ROOT
Tags : ,

[問題] 如何讓連結點擊無效

使用 javascript: void(0)

<a href="javascript: void(0)">點我無效</a>
Tags :