admin管理员组

文章数量:1415100

I have 2 links. In a session i store some data. I want if a user click in a specific link to look into the session and if the appropriate value contained, to continue. Else an AJAX pop up block will appears.

JAVASCRRIPT pop up block

 function displaymessage(title,message,close)
 {

        resultReturn= $.confirm({
        'title'     : title, 
        'message'   : message
        'buttons'   : {
        close/*'Yes'*/  : {
                'class' : 'blue',
                                    'caption': close,
                'action': function(){}
                        }           
                        }
                          });
   }

JSP with JSTL tags:

    <div class="header">
        <a href="<c:url value='/home'/>">
        <a href="<c:url value='/further'/>">
    </div>

     <c:if test="${not fn:containsIgnoreCase(data, 'mykey')}"> 
            <a id="get" class="right keepScrollPosition" 
               onclick="return displaymessage('<spring:message code="access.denied.title"/>'
                   ,'<spring:message code="access.denied.message"/>','<spring:message code="access.denied.close"/>');" 
               href="#"  /></a> 
        </c:if>

For example, if in the session contained the value 'mykey',then can go into the link home, else a pop up will appears. In case, in the session contained the value 'mypassword' and select the further link can continue, but if select the home link a pop up block will appears. I'm stuck and i need some help on how can i do this.Please help me

UPDATE

I'm trying the following script but it doesn't work:

  <li><a href="<c:url value='/home/'/>"<spring:message code="home_page"/>
        onclick="if(<c:if test="${not fn:containsIgnoreCase(data, 'mykey')}">){
                    return displaymessage('<spring:message code="access.denied.title"/>' 
               ,'<spring:message code="access.denied.message"/>','<spring:message code="access.denied.close"/>')" href="#" ;
       }
       </a>
   </li>

I have 2 links. In a session i store some data. I want if a user click in a specific link to look into the session and if the appropriate value contained, to continue. Else an AJAX pop up block will appears.

JAVASCRRIPT pop up block

 function displaymessage(title,message,close)
 {

        resultReturn= $.confirm({
        'title'     : title, 
        'message'   : message
        'buttons'   : {
        close/*'Yes'*/  : {
                'class' : 'blue',
                                    'caption': close,
                'action': function(){}
                        }           
                        }
                          });
   }

JSP with JSTL tags:

    <div class="header">
        <a href="<c:url value='/home'/>">
        <a href="<c:url value='/further'/>">
    </div>

     <c:if test="${not fn:containsIgnoreCase(data, 'mykey')}"> 
            <a id="get" class="right keepScrollPosition" 
               onclick="return displaymessage('<spring:message code="access.denied.title"/>'
                   ,'<spring:message code="access.denied.message"/>','<spring:message code="access.denied.close"/>');" 
               href="#"  /></a> 
        </c:if>

For example, if in the session contained the value 'mykey',then can go into the link home, else a pop up will appears. In case, in the session contained the value 'mypassword' and select the further link can continue, but if select the home link a pop up block will appears. I'm stuck and i need some help on how can i do this.Please help me

UPDATE

I'm trying the following script but it doesn't work:

  <li><a href="<c:url value='/home/'/>"<spring:message code="home_page"/>
        onclick="if(<c:if test="${not fn:containsIgnoreCase(data, 'mykey')}">){
                    return displaymessage('<spring:message code="access.denied.title"/>' 
               ,'<spring:message code="access.denied.message"/>','<spring:message code="access.denied.close"/>')" href="#" ;
       }
       </a>
   </li>
Share Improve this question edited Jul 8, 2012 at 14:06 Alex Dowining asked Jul 8, 2012 at 12:04 Alex DowiningAlex Dowining 9705 gold badges19 silver badges41 bronze badges 3
  • I don't know how can i do this.I need some directions – Alex Dowining Commented Jul 8, 2012 at 12:55
  • Don't know how to do what specifically? – Dave Newton Commented Jul 8, 2012 at 13:52
  • How to write the appropriate script in order to check in the session if the appropriate value contained.Probably i need an if statement bined with the onclick method. I update my code,please take a look. – Alex Dowining Commented Jul 8, 2012 at 13:56
Add a ment  | 

1 Answer 1

Reset to default 2

You can't use client-side JS to check a server-side value held in the session. Instead, you need to use JS to make a GET call to a request mapping which runs servers-side code to check the session. Flow could be as follows:

  1. User clicks button/image/something on page
  2. JS fires from click, makes AJAX call (e.g. $.get) to request mapping /check_session.do
  3. Request mapping checks session for value, returns true or false as JSON
  4. Client-side JS processes returned JSON, blocks or proceeds based on returned value

Alternatively, use JSTL to access the session and write the session field's value to a hidden form field on the page, which the client-side JS then reads. Example: http://www.steve-farmer./examples/el/ui/ses-attr-name.jsp

本文标签: javascriptJSP and JSTL with the Onclick methodStack Overflow