I have set the user ID and password values from a login page for a session using the following code in a .jsp file:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<script>alert("Hey")</script>
<%
String userName = request.getParameter("username");
String password = request.getParameter("password");
session.setAttribute("username", userName);
session.setAttribute("password", password);
response.sendRedirect("somefile.jsp");
%>
</body>
I want to access the username in a .js file, to send it to REST API. Tried this:
var uName = <%=session.getAttribute("username")%>;
But that doesn't work, since <% won't get parsed as needed in a .js file. Any suggestions?