Here is a short update on the case. Nashorn is working as expected. request.getCookies() works, as well as to create an instance of the class Cookie. For example, after creating the cookie I can use getName() or getValue() and it works perfectly fine.
The issue that I had with not seeing the cookie in the browser still exists, but that seems to be unrelated to Nashorn. Best Regards Simon Am Mi., 9. Nov. 2022 um 15:55 Uhr schrieb Simon Besenbäck < [email protected]>: > I do not get an exception. When opening the JSP in the Browser I see that > there is no Cookie created. > > The Code I am using: > > var lastVisit; > var allCookies = request.getCookies(); > > if (allCookies != null) { > for (var i = 0; i < allCookies.length; i++) { > var c = allCookies[i]; > if (c.getName() == 'lastVisit') { > lastVisit = c.getValue(); > } > } > } > > if (lastVisit == null) { > print("This is your first Visit!"); > } else { > print("Your last visit was at " + lastVisit); > } > > var Cookie = Java.type("jakarta.servlet.http.Cookie"); > var newCookie = new Cookie("lastVisit", "Test"); > response.addCookie(newCookie); > > Using request and response is possible due to this taglib: > https://sourceforge.net/projects/bsf4oorexx/files/Sandbox/rgf/taglibs/ga/ > > Best Regards > Simon > > Am Mi., 9. Nov. 2022 um 13:59 Uhr schrieb Attila Szegedi < > [email protected]>: > >> How is it not working? What is the exception you’re getting? >> >> On 2022. Nov 9., at 11:48, Simon Besenbäck <[email protected]> >> wrote: >> >> You should be able to create Java classes in Nashorn like this: >> >> var HashMap = Java.type("java.util.HashMap")var mapDef = new HashMap()var >> map100 = new HashMap(100) >> >> source: >> https://docs.oracle.com/javase/9/nashorn/nashorn-java-api.htm#JSNUG115 >> >> However when I try to use the jakarta.servlet.http.Cookie class it does >> not work. >> >> My Code: >> >> var Cookie = Java.type("jakarta.servlet.http.Cookie");var newCookie = new >> Cookie("lastVisit", "Test"); >> >> Does anyone know why this is not working or what I`m doing wrong? >> Best Regards >> Simon >> >> >>
