无法打开网址。请检查此网址是否正确

Ami*_*nov 5 java tomcat intellij-idea maven

我正在 Intellij(版本 14.0.3)中使用 Tomcat(Maven 项目)开发一个非常简单的 Java Web 应用程序。

当我编译和部署包(命令:“ mvn clean package:使用 Intellij)然后运行程序时,我得到一个弹出窗口:

Cannot open url. Please check this url is correct. 
Run Code Online (Sandbox Code Playgroud)

网址是“ http://localhost:8080/TimeDisplay/ShowTime.html”。

不用说,当我尝试直接通过浏览器访问此 URL 时,我会到达我创建的页面。

以下是项目运行配置的相关字段:

  • 应用服务器:Tomcat 9.0.0.M3

  • 打开浏览器:启动后选择 Firefox 作为选择的浏览器。该链接与我在错误中得到的链接相同。

  • 在“更新”操作上:重新启动服务器

  • 在帧停用时:什么都不做

  • Tomcat 服务器设置

  • HTTP 端口:8080
  • JMX 端口:1099

在部署选项卡下,我添加了“TimeDisplay:war 爆炸”(TimeDisplay 是我的项目名称)。

pom.xml的如下:

<project xmlns="removed link due to low stackoverflow reputation" xmlns:xsi="removed link due to low stackoverflow reputation"
 xsi:schemaLocation="removed link due to low stackoverflow reputation">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.amin</groupId>
  <artifactId>TimeDisplay</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>TimeDisplay Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.24.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.24.1</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>TimeDisplay</finalName>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

我还附上了我的项目结构的屏幕截图。

项目结构

值得注意的是,我一开始可以通过 Intellij 运行该程序,但我没有做任何更改就突然出现了这个问题。目前我正在打包我的代码并在Tomcat中手动部署它,这太可怕了!

Dav*_*dky 6

无法在外部 Web 浏览器中显示网页的原因可能还有更多。就我而言,问题在于 Idea 尝试检测应用程序部署的方式。

我的 Web 应用程序使用单点登录,当在没有身份验证的情况下发出请求时,应用程序会将用户重定向到外部站点进行登录。但是 IntelliJ Idea 可能会尝试等待 200 响应,并向我的应用程序发送大量请求。对于未经身份验证的用户,应用程序的正确响应是 302。当它在某个特定时间范围内没有发生时,Idea 会抱怨无法显示页面,甚至不会尝试打开浏览器。


Ami*_*nov 4

好吧,我解决了这个问题。IntelliJ 14.0.3 似乎有一个 bug。我删除了运行配置并使用相同的参数再次创建它,它立即开始工作。因此,作为解决方法,重新创建配置可以解决该问题。