简体   繁体   English

用ajax和javascript重新加载jsp自定义标签

[英]reload jsp custom tag with ajax and javascript

I have one jsp with some custom tag . 我有一个带有一些custom tag jsp Because of the security concerns, I have changed the tag file as the following. 由于安全方面的考虑,我将标记文件更改为以下内容。 The field will be rendered as <label> when ever it contains readonly data and it will rendered as text field when it doesn't contain readonly data. 如果该字段包含只读数据,则将显示为<label>如果不包含只读数据,则将显示为text field

Below is the code I use. 下面是我使用的代码。

<c:choose>
    <c:when test="${prot==true}">
         <label id="${jsvarname}">${status.value}</label>
    </c:when>
    <c:otherwise>
         <input type="text" name="${valueLocation}" id="${jsvarname}"/>
    </c:otherwise>
 </choose>

where prot is the value which specifies the field is readonly or not. 其中prot是指定字段为只读的值。

And now my problem is, by any javascript event, it can be changed to either of the fields. 现在我的问题是,通过任何javascript事件,都可以将其更改为任意一个字段。 So I want to go for ajax to refresh the field. 因此,我想使用ajax刷新该字段。 I know how to populate the data through ajax request. 我知道如何通过ajax请求填充数据。 But I couldn't find any clue to reload the jsp custom tag with ajax request. 但是我找不到任何线索来用ajax请求重新加载jsp custom tag

I am using spring mvc. 我正在使用Spring MVC。

Any help with some code snippet will be appreciated. 任何帮助与一些代码片段将不胜感激。

Thanks in advance. 提前致谢。

Offhand, I would suggest you implement a controller method that returns a view (JSP) that only contains your custom tag. 另外,我建议您实现一个控制器方法,该方法返回仅包含自定义标记的视图(JSP)。

fragment.jsp: fragment.jsp:

<mytag prot="${protValue}" jsvarname="${jsvarnameValue}" valueLocation="${valueLocationVal}"/>

FragmentController: FragmentController:

@RequestMapping(value="/fragment-view", method = RequestMethod.GET)
public String getFragment(ModelMap model) {
    model.put("protValue", ...);
    model.put("jsvarnameValue", ...);
    model.put("valueLocationVal", ...);
    return "fragment";
}

You only have to invoke that method with AJAX and replace the old fragment with the html returned by the server. 您只需使用AJAX调用该方法,并将旧片段替换为服务器返回的html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM