Tag: tomcat

[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 :

[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 :

[問題]如何在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 : ,