最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - passing value to JavaScript from JSP - Stack Overflow

programmeradmin4浏览0评论
<%   if(empRecNum != null && !(empRecNum.equals("")))
        {
           empSelected=true;
        }
        boolean canModify = UTIL.hasSecurity("PFTMODFY") && empSelected;
%>

<script type="text/javascript">

    function add(){
        alert(canModify);
        df('ADD');
    }

</script>

I need to alert the canModify in my JavaScript

<%   if(empRecNum != null && !(empRecNum.equals("")))
        {
           empSelected=true;
        }
        boolean canModify = UTIL.hasSecurity("PFTMODFY") && empSelected;
%>

<script type="text/javascript">

    function add(){
        alert(canModify);
        df('ADD');
    }

</script>

I need to alert the canModify in my JavaScript

Share Improve this question edited Oct 25, 2010 at 14:10 Jigar Joshi 241k42 gold badges409 silver badges446 bronze badges asked Oct 25, 2010 at 14:06 JohnJohn 1,1893 gold badges19 silver badges29 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

I know I use something like this:

<%
String s = "BOB";
%>
<script>
alert('<%= s %>');
</script>

The '<%= %>' tag lets you put in the value of the java variable.

Get away from using scriptlets, use jstl and expression language and it would look like this:

alert( ${UTIL.hasSecurity("PFTMODFY") 
         && empRecNum != null 
         && !(empRecNum.equals("")
        }
      );

Do some thing like.

function add(){
        alert(<%=canModify%>);
        df('ADD');
    }
发布评论

评论列表(0)

  1. 暂无评论