当前位置: 首页 > 知识库问答 >
问题:

Tomcat在http://localhost:8080/中工作,但在尝试http://localhost:8080/page/home.jsp时不工作

欧阳德运
2023-03-14

步骤:

  • 在Tomcat服务器上单击右键>属性
  • 在常规菜单中:单击切换位置
  • 位置已从[workspace metadata]更改为位于localhost.Server的/Server/Tomcat V8.5服务器

在此配置之后,我再次启动tomcat服务器,http://localhost:8080/现在正在工作。我可以看到Tomcat欢迎页面

HTTP Status 404 – Not Found
127.0.0.1 - - [04/Oct/2018:09:42:30 -0300] "GET /EventryApp/hello.jsp HTTP/1.1" 404 1098

按照我的设置文件:

eventryapp/pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>br.com.eventryapp</groupId>
<artifactId>EventryApp</artifactId>
<version>1.0.0-CI-SNAPSHOT</version>
<packaging>jar</packaging>
<name>EventryApp Maven Webapp</name>

<properties>
    <maven.test.failure.ignore>true</maven.test.failure.ignore>
    <spring.framework.version>3.2.0.RELEASE</spring.framework.version>
    <hibernate.version>4.1.9.Final</hibernate.version>
    <sl4j.version>1.7.2</sl4j.version>
    <junit.version>4.11</junit.version>
    <hsqldb.version>2.2.9</hsqldb.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
                <sourceIncludes>
                    <sourceInclude>**/*.*</sourceInclude>
                </sourceIncludes>
            </configuration>
        </plugin>
        <!-- Configuration which allows JUnit tests to be placed in the same folder as java files -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <testSourceDirectory>${basedir}/src/main/java/</testSourceDirectory>
                <testClassesDirectory>${project.build.directory}/classes/</testClassesDirectory>
            </configuration>
        </plugin>
    </plugins>
    <!-- Configuration which allows configuration files (such as xml files) to be placed in the same folder as java files -->
    <resources>
        <resource>
            <directory>${basedir}/src/main/java/</directory>
        </resource>
    </resources>
</build>


<dependencies>
    <!-- ********************************************************************** 
         **                 SPRING DEPENDENCIES                              ** 
         ********************************************************************** -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>


    <!-- ********************************************************************** 
         **                 HIBERNATE DEPENDENCIES                           ** 
         ********************************************************************** -->

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>



    <!-- ********************************************************************** 
         **                 OTHER DEPENDENCIES                               ** 
         ********************************************************************** -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jcl</artifactId>
        <version>${sl4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${sl4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>${hsqldb.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>


    <!-- ********************************************************************** 
        ** TEST DEPENDENCIES 
    ** ********************************************************************** -->

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>

</dependencies>

eventryapp/src/main/webapp/WEB-INF/web.xml

<web-app id="WebApp_ID" version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Archetype Created Web Application</display-name>

    <context-param>
        <param-name>ApplicationContext</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</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:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- Enable autowire -->
    <context:annotation-config />
    <context:component-scan base-package="com" />

    <mvc:annotation-driven />

    <mvc:resources mapping="/resources/**" location="/resources/" />

    <!-- If you use MySQL Database comment out this bean and let others commented  -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" ></property>
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/eventrydb" > </property>
       <property name="username" value="root" ></property>
       <property name="password" value="" ></property>
    </bean>

    <!-- SQL Server 2012 and 2014 Database drivers and connectivity code -->
    <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" ></property>
    <property name="url" value="jdbc:sqlserver://localhost;databaseName=mydb" ></property>
    <property name="username" value="sa" ></property>
    <property name="password" value="abcd@1234" ></property>
</bean> -->

    <!-- Session Factory Declaration -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" ></property>
        <property name="packagesToScan" value="com.entities" ></property>
        <property name="hibernateProperties">
        <props>
            <!-- SQL Dialect -->
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

            <!-- SQL Server 2014 Dialect -->
            <!-- <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> -->

            <!-- Your required Database Name -->
            <prop key="hibernate.default_schema">eventrydb</prop>

            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.enable_lazy_load_no_trans">true</prop>
            <prop key="format_sql">true</prop>
            <prop key="use_sql_comments">true</prop>
        </props>
    </property>
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

 <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" ></property>
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/views/" ></property>
      <property name="suffix" value=".jsp" ></property>
    </bean> 
</beans>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
  <html>
     <head>
        <meta charset="ISO-8859-1">
        <title>Eventry API</title>
     </head>
      <body>
        <h1>Hello Eventry API</h1>
      </body>
  </html>

共有1个答案

宰父飞白
2023-03-14

首先。对于本地tomcat所在的测试或开发目的来说,我根本无关紧要。我正在使用标准服务器位置(使用工作区元数据)。但这和你的问题无关。

其次,必须配置应用程序的基本路径。通常,这是在您将应用程序添加到服务器时完成的(例如,当您使用Eclipse时)

如果这不是自动完成的,则必须在server.xml文件中写入以下内容

<Context docBase="myApp" path="/myApp" reloadable="true" source="org.eclipse.jst.jee.server:myApp"/>
@Controller
@RequestMapping(value="/")
@Scope(value="session")
public class MainController {

  @RequestMapping
  public ModelAndView mainView() {
    ModelAndView mav = getModelAndView("mainView");
    return mav;
  }

}
 类似资料:
  • 我在这里的问题中遇到了同样的问题:Tomcat在eclipse中启动,但无法连接到http://localhost:8085/,这意味着我无法在浏览器上打开http://localhost:8080/: 我使用的是Tomcat 7.0.27、Eclipse Europa和Java1.6.0_32。我看到了Balusc的答案,但问题是我无法选择Tomcat安装(下图)。 这里会出什么问题? PS:似

  • 我在8080端口创建了一个简单的服务器,并使用three.js在我的超文本标记语言文档中加载GLTF文件。这里是服务器端代码,然后是超文本标记语言代码。 现在获取错误-:8080/:1获取http://localhost:8080/404(好)我的两个文件都命名为1。js和1。html。 此外,它还有两个警告- DevTools未能加载SourceMap:无法加载chrome的内容-extensi

  • 下面是pom.xml 日志清楚显示为Tomcat服务器以8080端口号启动 2018-12-19 17:04:35.198信息709136---[nio-8080-exec-1]O.s.web.Servlet.DispatcherServlet:初始化Servlet“Dispatcher Servlet”2018-12-19 17:04:35.198信息709136---[nio-8080-exe

  • 我正在Angular 9上开发一个小型宠物项目,并想尝试将其转换为PWA。已经按照指南去做了(特别是https://medium.com/javascript-in-plain-english/convert-your-angular-app-into-a-pwa-in-2019-the-painless-guide-bbf523d2ce72)。 尝试寻找解决方案,清理缓存,重建项目,更改应用程序

  • 使用Spring Boot(后端)和React(前端)开发时,我有一个奇怪的行为。React和Spring boot都在本地主机8080上运行。 当我从React to Spring Boot向localhost:8080发送POST请求时,我在Spring Boot中遇到了以下错误: 当我从localhost:3000(React development build)向localhost:808

  • 当我使用HTML2Canvas评估图像时,我得到了这个错误。 CORS策略阻止从来源“http://localhost:8080”访问位于“http://testdomain.com/storage/images/products/user_front.png”的映像:请求的资源上没有“Access-Control-Allow-Origin”标头。 下面是我的cors配置。 有人能帮我吗?