2017-01-18 11 views

答えて

0

No.セッションはサーバサイドの概念です。

`request.getSession().getAttribute("username)`. 

<script> 
    var userID = <% out.print(userID); %>; 
</script> 
0

は、あなたがこのように必要なパラメータを取得するためにrequestオブジェクトを使用するか、代わりにELを使用する:あなたは、クライアント側にその情報が必要な場合は、お使いのサーバー側のコードが明示的に沿って渡しています。あなたのJSPファイルに

`<%@page isELIgnored="false"%>` 

を追加することを忘れないでください。

ELは、action scopeでパラメータの値を選択します。その後、 原因requestScope < sessionScoperequestScope'username'sessionScopeというパラメータがありますならば、それは最初のrequestScopeで値を検索し、選択されますので、sessionScope、そして... ただ、以下のコードのように:

<script type="text/javascript"> 
     /* test in my own jsp file with isELIgnored="false" 
      <%@ page language="java" contentType="text/html; charset=UTF-8" 
      pageEncoding="UTF-8" isELIgnored="false"%> 
      <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
     */ 
     <% request.getSession().setAttribute("author", "Vincent"); %> 
     var author = "<%= request.getSession().getAttribute("author") %>"; 
     alert(author); 
     author = "${sessionScope.author}"; 
     alert(author); 
</script> 
関連する問題