开发者

Using jQuery to show div depending on return value from servlet

I want to use the language parameter returned through servlet to decide which div to view, I am using jsp/servlet technieque,

I receive lang param from request

<c:set var="lang" value="${lang}" scope="requ开发者_开发知识库est"></c:set>

how can I use jquery to solve this thing?


You would assign your JSTL parameter to a JavaScript variable:

<script type="text/javascript">
var lang = "${lang}";  // When JSP gets processed, this becomes var lang = "EN", etc.

$("#"+lang).show();    // Assumes you have a div id="EN" or whatever.
</script>


You can decide this on the server since you have the information that you need there. FOr instance:

 <c:choose>
    <c:when test='${lang=="EN"}'>
       <div>English</div>
    </c:when>
    <c:when test='${lang=="ES"}'>
       <div>Espaniol</div>
    </c:when>
 </c:choose>

I am not sure where jQuery comes in since that is on the client.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜