tomcat - 将tomcat配置为仅将一个网站作为默认网站

标签 tomcat tomee

我被迫将网站移至静态IP。这要求我更改tomcat(Tomee-Plume)上的配置。我不知道该怎么做,直接将端口80映射到该网站。因此,例如,旧电视机具有以下隐身转发设置。

旧的隐形设置。

my.domain-> http://999.999.999.999/Websites/HomeServlet

现在,我需要将“ / Websites / HomeServlet”部分的分辨率推入tomcat(Tomee-Plume)配置中,因为我仅使用互联网“ A”记录将域名映射到IP。无法将“ / Websites / HomeServlet”部分放入互联网“ A”记录中。

我猜这种设置很普遍,但是我不知道在进行互联网搜索时通常被称为什么。



下面的内容是根据Shankar PS的要求添加的内容。



Eclipse中的文件布局


/网站/网站/ src software.website
/Website/src/software/website/About_UsServlet.java
/Website/src/software/website/Call4betatestersServlet.java
/Website/src/software/website/ConsultingServlet.java
/Website/src/software/website/ContactUsFormPostServlet.java
/Website/src/software/website/ContactUsServlet.java
/Website/src/software/website/ContactUsThankYou.java
/Website/src/software/website/ContributorsServlet.java
/Website/src/software/website/DonateServlet.java
/Website/src/software/website/EditionsServlet.java
/网站/ src /软件/网站/Footer.java
/Website/src/software/website/ForumsServlet.java
/Website/src/software/website/Free_license_contestServlet.java
/网站/ src /软件/网站/Header.java
/Website/src/software/website/HomeServlet.java
/Website/src/software/website/LoginServlet.java
/网站/ src /软件/网站/Menu.java
/Website/src/software/website/MM_Quality_Assurance_GatesServlet.java
/Website/src/software/website/MM_RepositoryServlet.java
/Website/src/software/website/News_letter_signupServlet.java
/Website/src/software/website/PerspectivesServlet.java
/Website/src/software/website/SendEmail.java
/网站/ src /软件/网站
/SR_Repository_Quality_Assurance_GatesServlet.java
/Website/src/software/website/SR_RepositoryServlet.java
/Website/src/software/website/TabMenu.java /Website/.settings
/网站/构建/网站/ WebContent /网站/ WebContent / META-INF
/网站/ WebContent /样式/网站/ WebContent / WEB-INF
/ Website / WebContent / WEB-INF / lib /Website/WebContent/WEB-INF/web.xml
/Website/.classpath /Website/.project




头文件

package software..website;

public class Header {

    public Header() {
    }

    static StringBuffer getStandardHTMLHeader(){
        StringBuffer sb = new StringBuffer();
        sb.append("<?xml version='1.0' encoding='UTF-8'?> ");
        sb.append(
                "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>");
        sb.append("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>");
        sb.append("<head>");
        sb.append("<meta http-equiv='content-type' content='text/html; charset=UTF-8' />");
        sb.append("<META NAME=\"ROBOTS\" CONTENT=\"NOINDEX, NOFOLLOW\" />");
        sb.append("<META NAME=\"description\" content=\" is a software application that does mathematical models of the space elevator.\" />");

        sb.append("<!-- **** layout style-sheet **** -->");
        sb.append("<link rel='stylesheet' type='text/css' href='./style/style.css' />");

        sb.append("<!-- **** color scheme style-sheet **** -->");
        sb.append("<link rel='stylesheet' type='text/css' href='./style/blue.css' />");
        sb.append("</head>");
        return sb;

}

}




HomeServlet.java

package software..website;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class home
 */
@WebServlet("/HomeServlet")
public class HomeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public HomeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        // response.getWriter().append("Served at:
        // ").append(request.getContextPath());
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        try {

            out.println(Header.getStandardHTMLHeader() );

            out.println("<body>");

            out.println(Menu.getStandardHTMLMenu());


            blah, blah, blah......
            blah, blah, blah......
            blah, blah, blah......


            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}




web.xml

<?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" 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></display-name>
  <description>
    The web site for  software
    </description>
<!-- -->
  <servlet>
    <servlet-name>HomeServlet</servlet-name>
    <servlet-class>software..website.HomeServlet</servlet-class>
     <init-param>
        <param-name>isVirtualWebappRelative</param-name>
        <param-value>1</param-value>
     </init-param>    
  </servlet>
<servlet-mapping>
  <servlet-name>HomeServlet</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping> 
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Protect Donation page</web-resource-name>
        <url-pattern>/DonateServlet</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>        
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>  
</web-app>




** web.xml v2 **


http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd“ id =” WebApp_ID“ version =” 3.0“>

<!-- ========================================================== -->
<!-- General Info -->
<!-- ========================================================== -->
<display-name>Abc</display-name>
<description>
   The web site for Abc software
</description>

<!-- ========================================================== -->
<!-- Home Servlet -->
<!-- ========================================================== -->
<servlet>
   <servlet-name>HomeServlet</servlet-name>
   <servlet-class>software.abc.website.HomeServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
 </servlet>

<!-- Map the HomeServlet name to the URI /HomeServlet (main page for site) --> 
 <servlet-mapping>
   <servlet-name>HomeServlet</servlet-name>
   <url-pattern>/AbcLandingPage</url-pattern>
 </servlet-mapping> 

 <security-constraint>
     <web-resource-collection>
         <web-resource-name>Protect Donation page</web-resource-name>
         <url-pattern>/DonateServlet</url-pattern>
         <http-method>GET</http-method>
         <http-method>POST</http-method>        
     </web-resource-collection>
     <user-data-constraint>
         <transport-guarantee>CONFIDENTIAL</transport-guarantee>
     </user-data-constraint>
 </security-constraint>  


<!-- ========================================================== -->
<!-- Welcome Files -->
<!-- ========================================================== -->

<!-- The main page for the site will be the HomeServlet servlet (http://website/AbcLandingPage) -->
<!-- No mapping is defined for other folders (http://website/someFolder/AbcLandingPage), -->
<!-- so one of the other files will be displayed (index.html, index.htm, index.jsp) -->
<welcome-file-list>
    <welcome-file>AbcLandingPage</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>






仍然会获得tomcat欢迎页面。

enter image description here



这适用于我的Windows 7工作站和Eclipse Mars 2(4.5.2)

  <Context docBase="Websites" path="" reloadable="true" source="org.eclipse.jst.jee.server:Websites"/></Host>


但这在我的Fedora 23服务器上不起作用。

    <Context path="/Websites" docBase="Websites/HomeServlet" debug="0" reloadable="true"></Context>




视窗7(Works)

"C:\apache-tomee-plume\wtpwebapps\Websites\WEB-INF"
"C:\apache-tomee-plume\wtpwebapps\Websites\META-INF"
"C:\apache-tomee-plume\wtpwebapps\Websites\style"


Fedora 23(抛出异常)

/opt/tomee/webapps/docs/{the directory has files in it}
/opt/tomee/webapps/host-manager/{the directory has files in it}
/opt/tomee/webapps/manager/{the directory has files in it}
/opt/tomee/webapps/ROOT/{the directory has files in it}
/opt/tomee/webapps/Websites/{the directory has one directory, no files in it}
/opt/tomee/webapps/Websites/HomeServlet.unpacked/{the directory is empty}
/opt/tomee/webapps/Websites.war

最佳答案

您需要做两件事。将Tomcat的默认端口从8080更改为80,并允许对Tomcat的请求命中您的项目。尝试这个。

在文件{TOMCAT_CATALINA} /conf/server.xml中,查找协议HTTP / 1.1的连接器标记。它将映射到8080。将其更改为80,如下所示。

<Connector port="80" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
    maxThreads="750"
    acceptCount="750"
    redirectPort="8443" />


然后,在同一文件中的Host标记下添加它。 (我假设您的WAR文件名为“网站”。这在此页的方法2.1中进行了解释-http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application.3F

<Context path="" docBase="Websites" debug="0" reloadable="true"></Context>


现在,对http://my.domain的调用将到达您的WAR文件。

接下来,将servlet映射到项目的web.xml中的默认路径。

<servlet-mapping>
  <servlet-name>HomeServlet</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping> 


现在,对http://my.domain的调用等效于http://YOUR_IP/Websites/HomeServlet

关于tomcat - 将tomcat配置为仅将一个网站作为默认网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38132612/

相关文章:

eclipse - 浏览到 Eclipse mars 版本中的 Tomcat 安装目录

java - index.html 404 - 在 tomcat 服务器中找不到

tomcat - m2eclipse 和 tomcat

java - 如何在Tomee中删除HSQLDB数据源?

tomcat - 无法使用 JDK6 生成 keystore ,但可以使用 JDK5 生成

apache - 当 default virtualhost 不可用时,没有可用的虚拟主机