Java 单击按钮时路由到其他应用程序

Java 单击按钮时路由到其他应用程序,java,nginx,Java,Nginx,为了学习nginx,我创建了2个javaweb应用程序。 目前,我可以通过修改nginx.conf文件,在点击localhost时路由到我的一个web应用程序 在我的应用程序中,有一个单击此处链接。我正试图点击我的第二个网络应用。我怎样才能做到这一点 Mynginx.confserver指令片段-: server { listen 80; server_name localhost; #charset koi8-r;

为了学习nginx,我创建了2个javaweb应用程序。 目前,我可以通过修改
nginx.conf
文件,在点击
localhost
时路由到我的一个web应用程序

在我的应用程序中,有一个
单击此处
链接。我正试图点击我的第二个网络应用。我怎样才能做到这一点

My
nginx.conf
server指令片段-:

 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        proxy_pass http://127.0.0.1:8081/Hello_World/;
        }
    location /saytime {
            root   html;
            index  index.html index.htm;
        proxy_pass http://127.0.0.1:8080/FirstServletProject/FirstServlet/;
        }
运行在
http://127.0.0.1:8081/Hello_World/

第二台服务器正在
http://127.0.0.1:8080/FirstServletProject/FirstServlet/

我的你好世界
index.html
文件-:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
<a href="saytime">Click Here</a>
</body>
</html>

因此,当用户单击HTML时,您的HelloWorld服务器必须重定向到FirstServletProject服务器

  • 还可以看看Nginx服务。有时,配置中的错误不允许启动服务。使用
    systemctl status nginx
    查看它是否正在运行。如果没有,请使用
    journalctl-e
    调试错误

  • 编辑 与OP讨论后,所提供的解决方案均无效

    尝试在Nginx conf中创建另一个服务器块(与默认块不同)并为每个服务器创建上游块:

    server {
          listen 8082;
          location / {
             proxy_pass http://helloworld;
          }
          location /saytime/ {
             proxy_pass http://firstservlet;
          }
       }
    
       upstream helloworld {
          server http://127.0.0.1:8081/;
       }
    
       upstream firstserver {
          server http://127.0.0.1:8080/;
       }
    
    

    我想你应该un注释
    @WebServlet(“/saytime”)
    注释。

    我按照你的注释尝试了-1。将我的控制器移动到
    FirstServletProject
    。2.评论了
    @WebServlet(“/saytime”)
    .3。将href更改为绝对路径。我仍然没有得到回应。你能帮我举个例子吗?你确定Nginx运行正确吗?你用的是Linux还是Windows?我用的是Mac系统。是的,它正在运行。第一个路由
    /
    正在正确进行。当我点击
    localhost
    时,如果您试图从web浏览器发出请求,会发生什么?安装Postman,执行请求并粘贴或解释您得到的响应。谢谢Victor。我可以用你在答案中的指针来解决它。
    Type Status Report
    
    Message /FirstServletProject/FirstServlet/
    
    Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
    
    server {
          listen 8082;
          location / {
             proxy_pass http://helloworld;
          }
          location /saytime/ {
             proxy_pass http://firstservlet;
          }
       }
    
       upstream helloworld {
          server http://127.0.0.1:8081/;
       }
    
       upstream firstserver {
          server http://127.0.0.1:8080/;
       }