我的 css 和 js assest 的本地链接在从链接重定向到页面时被附加到 localhost

My local links for css and js assest are getting appended with localhost while redirecting to a page from a link

本文关键字:链接 localhost 重定向 js css assest 我的      更新时间:2023-09-26

我通过电子邮件发送的激活链接:http://localhost:8080/respondToInvitation/example@gmail.com/1

我在我的java控制器中使用此链接来获取一个具有要激活的相应电子邮件ID的帐户,我的代码是这样的激活:

@RequestMapping(value = "/respondToInvitation/{email}/{id}", method = RequestMethod.GET)
public String respondToInvitationByEventCode(ModelMap modelMap,@PathVariable String id,@PathVariable String email){ 
    log.debug("Begin->respondToInvitationByEventCode::");
    User user = userDAO.getUserByEmail(email);
    if (user!= null && user.getId() != 0) {
        modelMap.put("status", "failure");
        modelMap.put("message", "The Email you entered is already registered!");
    } else {
        user = new User();
        user.setEmailId(email);
        user.setId(NumberUtils.toLong(id));
    }
    modelMap.put("user", user);
    return PageView.DEPENDANTSIGNUP;
  }

现在,当我从邮件中单击上面的链接时,我收到我在JSP页面中使用的CSS和JS的404错误。它显示这个:http://localhost:8080/respondToInvitation/pavankalyan.tolety12@gmail.com/css/bootstrap.min.css localhost:8080/后面必须跟着 CSS 和 js 脚本。我在java或邮件链接中犯的错误在哪里?

你可以

使用../../跳到斜杠上方 2 次。../表示一次跳入网址。

<link rel="stylesheet" href="../../../css/bootstrap.min.css" type="text/css" /> 

<link rel="stylesheet"href="http://localhost:8080/respondToInvitation/css/bootstrap.min.css " type="text/css" /> 

<link rel="stylesheet"href="${pageContext.request.contextPath}/css/bootstrap.min.css " type="text/css" />