java - 在 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>
但它不起作用。
解决方案
推荐阅读
- flutter - Flutter 如何合并数组
- javascript - 如何使前置元素在顶部溢出窗口?
- python-3.x - 如何使用 spotipy 从播放列表中获取 playlist_id?
- sql - SQL案例操作
- javascript - 反应道具中联合和交叉类型的问题
- python - Django 错误 ModelForm 没有指定模型类
- mysql - 如果没有第二个连接到第一个连接,如何将第一个连接的过滤器列表中的值添加到第一个连接的结果中,添加行值?
- javascript - 比较 postgres 时间戳和 JavaScript 日期对象
- laravel - 如何在 laravel 8 中使用关系
- javascript - 如何在 Firebase 中计算文档中的集合