首页 > 解决方案 > 在 jsp 页面中的 location.href 中传递当前用户名

问题描述

有可能吗?我想将用户传递给 servlet:

@WebServlet("/profile")

这样 URL 就变成了这样:/profile?username=currentusername

我试过了:

 <%
        HttpSession session1 = request.getSession(false);
        String username = (String) session1.getAttribute("username");
    %>
        <div class="navbar-item"
             onclick="location.href =
     '${pageContext.request.contextPath}/profile?username=${requestScope.username}'

            My profile
        </div>

但它不起作用。

标签: javajspservlets

解决方案


推荐阅读