开发者

problem dealing with request parameter using jsp within a javascript block

I've a jsp page which saves a request parameter inside a javascript variable. Say a user visits the page through a wish list then the param fromWishList is set to 1, if the user visits this page from other source then there is no param called fromWishList.

//following code is inside a jsp page
<script type="text/javascript">
  var isWishList = '<c:out value="${param.fromWishList}" />';
    if(isWishList != ''){
      //page visited via wishList
    } else {
      //page visited via other sources
    }
</script>

Now my problem is that if a user visits the page via wish list the javascript var isWishList is set permanently set to '1', so that if the same user visits the page again via other sources the isWishList is still set to '1'. In the second case i wanted it to be blank.

I'm struggling with this since long time. I app开发者_运维知识库reciate any help.


Try to take a look at the generated html code in your browser to see what values in both cases are assigned to the isWishList variable. You check for the empty string ''. You might better check for the string '1' because in the other case the value might be something like 'null' or similar. Don't know what jsp renders in this case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜