Struts2的jQuery插件响应Ajax和整个页面的HTML请求 [英] Struts2 jquery Plugin responds to ajax requests with HTML of the entire page
问题描述
我想使用Struts2的jQuery插件对我的一些形式的Ajax请求,但我有一个问题,响应页面。 Struts的Action进行验证,并正确执行,但在jQuery的得到响应,它设置响应,整个页面的HTML ...它是把在正确的位置的反应,但它不具有正确的事,在响应一切......这里是JSP表单:
I am trying to use the Struts2 jquery plugin for ajax requests on some of my forms, but I am having an issue with the response to the page. The struts action is validated and executed properly, but when jquery gets a response, it sets the response as the HTML of the entire page... It is putting the response in the correct place, but it is not responding with the right thing at all... Here is the jsp form:
<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<div class="columnbox">
<h2>Contact Us</h2>
<div id="contact">
<s:form id="contact_form" action="contact" method="post" cssClass="clearfix">
<label for="contact_user">Username / In-game name:</label>
<input type="text" id="contact_user" name="contactBean.username" class="field"
data-enter-click="sendbutton" maxlength="16" size="16" />
<div id="contact_response" class="response">
</div>
<sj:submit
formIds="contact_form"
id="sendbutton"
targets="contact_response"
value="Send"
button="true"
/>
</s:form>
</div>
</div>
这里是contactAction类的snipit:
And here is a snipit of the contactAction class:
public class ContactAction extends ActionSupport {
private static final long serialVersionUID = -5484167219440627408L;
private static final Log log = LogFactory.getLog(ContactAction.class);
private ContactBean contactBean;
@Override
public String execute() throws Exception {
log.info("TEST 4");
//Do email stuff
addActionMessage(Constants.EMAIL_SENT);
log.info(this.getActionMessages());
return Action.SUCCESS;
}
@Override
public void validate() {
System.out.println("TEST");
log.info("TEST 2");
//do validation
if (contactBean == null) {
addActionError("");
}
else if (contactBean.getUsername() == null || contactBean.getUsername().isEmpty()) {
addActionError(Constants.NO_USERNAME);
}
log.info(this.getActionErrors());
}
public ContactBean getContactBean() {
return contactBean;
}
public void setContactBean(ContactBean contactBean) {
this.contactBean = contactBean;
}
}
我是pretty的确认标记是完全应该的。请求被正确发送,响应正在:收到。这看起来像jQuery的一个问题... 感谢您的帮助
I am pretty sure that the tag is exactly how it should be. The request is being sent properly, and the response is being recieved. This looks like a problem with the jquery ... Thanks for your help
推荐答案
的响应是正是返回其执行后的结果的事情。无论结果被配置到结果返回作为响应,取其结果类型和结果code实际上返回这一切都取决于你的操作配置。
The response is exactly the thing that returned by the result after its execution. Whatever result is configured to return the result as a response, whichever result type and result code is actually returned it's all depends on your action configuration.
你有一个返回一整页,结果问题是因为当验证失败的输入
返回结果。你要么删除确认从堆栈或者
拦截它是一个调度
结果类型,更新执行结果前结果配置的位置
属性。
The problem you have that returns a whole page as a result is because the INPUT
result is returned when the validation fails. You have to either remove the validation
interceptor from the stack or if it's a dispatcher
result type, update the location
attribute of the result config before the result is executed.
这篇关于Struts2的jQuery插件响应Ajax和整个页面的HTML请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!