After the java project is published to the server, why is the middle link address still localhost??

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<link href="/ehouse/css/admin/login.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <div class="login">
            <h1></h1>
                

<input type="text" id="name" value="admin" placeholder="">

<input type="password" id="password" value="" placeholder="">

<p class="submit"> <input type="submit" id="commit" value="">

</div> </div> </body> </html> <script type="text/javascript" src="/ehouse/js/jquery-3.2.1.min.js"></script> <script type="text/javascript"> $("-sharpcommit").click(function(){ var name =$("-sharpname").val(); var password = $("-sharppassword").val(); if(name =="admin"&&password =="ehouse"){ location.href="<%=basePath%>admin/login.html"; }else{ alert(""); } }); </script>
Mar.01,2021

you may have used some proxies.

replace the absolute path with a relative path, like this

// location.href="<%=basePath%>admin/login.html";
location.href="/admin/login.html";
< hr >

by the way, it's inappropriate to write your user name and password in javascript. Anyone can see them

.
if(name =='admin'&&password =='ehouse'){

dude, why do you use java to do this user name and password after JS verification? It's not safe


you check to see if the local host file has changed.


it is recommended that you check whether there is a reverse proxy such as nginx / apache on the server. If so, the request header setting of the reverse proxy should be consistent with the request header of the request. This should have nothing to do with Java.


4L the answer should be positive solution. In the nginx configuration file, add
`
proxy_set_header Host $host;
proxy_set_header X_Real_IP $remote_addr;
`

under the location block.
Menu