鍍金池/ 問答/Java  HTML/ 為什么<a href="#">點(diǎn)擊后的鏈接不是當(dāng)

為什么<a href="#">點(diǎn)擊后的鏈接不是當(dāng)前頁面,而是項(xiàng)目根目錄后加#

問題:我在http://localhost:8080/ssm0702/user/getUsers寫了個(gè)登錄的超鏈接href="#",我以為他會(huì)跳轉(zhuǎn)到當(dāng)前頁面,結(jié)果跳轉(zhuǎn)到http://localhost:8080/ssm0702/#了
截圖:
圖片描述

圖片描述

頁面代碼:

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'allUsers.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
      <c:if test="${uname==null }"><a href="#">登錄</a></c:if>
      <c:if test="${uname!=null }">歡迎,${uname }登錄!</c:if>
      <c:if test="${uname!=null }"><a href="<%=basePath %>user/loginout">注銷</a></c:if>
    <center>
        <h1>用戶列表</h1>
        <table border="1">
            <tr>
                <td>用戶編號(hào)</td>
                <td>用戶名</td>
                <td>密碼</td>
            </tr>
            <c:forEach items="${users }" var="d">
                <tr>
                    <td><a href="#">${d.userid }</a></td>
                    <td>${d.username }</td>
                    <td><img alt="${d.pwd}" src="img/${d.pwd}"></td>
                </tr>
            </c:forEach>
        </table>
    </center>
  </body>
</html>
回答
編輯回答
失魂人

<base href="<%=basePath%>">

2017年11月6日 02:33
編輯回答
陌如玉

你為你頁面設(shè)置了 base.

<base href="<%=basePath%>">

不過不管有沒有 base, 頁面最后都是會(huì)被加上#的, 這是標(biāo)準(zhǔn)定義的行為. 基于你的需求, 你可以這么做

<a href="javascript:void(0)">登錄</a>
2018年8月17日 11:50