如何显示哪个用户登录到我的HTML

我有一个Java servlet,我正在验证哪个用户登录我将这些值存储到变量中我想要实现的是在我的欢迎页面上显示该用户是他的名字和公司名称这里是我的Json

[{"Name":"admin","Companyname":"ABC PVT LTD"}]

这是我的navebar

<nav class="navbar navbar-expand-sm bg-dark navbar-dark navbar fixed-top">

  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    			<span class="navbar-toggler-icon"></span>
    		</button>
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul id="navbarId" class="navbar-nav mr-auto">

    </ul>

  </div>

  <a class="navbar-brand" href="Header.html">HOME</a>

</nav>
<div style="padding: 30px"></div>



<div class="col-sm-12">
  //here i want to show like Welcome 'admin' - 'ABC PVT LTD'
  <hr style="border: solid 1px black">
</div>

回答(1)

2 years ago

你可以做 $(".name").text("Welcome '" +obj[0].Name + "'-" +obj[0].Companyname) 之类的事情

var obj = [{"Name":"admin","Companyname":"ABC PVT LTD"}];

$(".name").text("Welcome '" +obj[0].Name + "'-" +obj[0].Companyname)

Working demo

var obj = [{"Name":"admin","Companyname":"ABC PVT LTD"}];

$(".name").text("Welcome '" +obj[0].Name + "'-" +obj[0].Companyname)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav
        class="navbar navbar-expand-sm bg-dark navbar-dark navbar fixed-top">

        <button class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false"
            aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul id="navbarId" class="navbar-nav mr-auto">

            </ul>

        </div>

        <a class="navbar-brand" href="Header.html">HOME</a>

    </nav>
    <div style="padding: 30px"></div>



    <div class="col-sm-12">
        <div class="name"></div>
        <hr style="border: solid 1px black">  
    </div>