我正在尝试在我的某些表单上使用 Struts2 jquery 插件来处理 ajax 请求,但我对页面的响应有问题。struts 动作经过验证并正确执行,但是当 jquery 获得响应时,它将响应设置为整个页面的 HTML ...它将响应放在正确的位置,但它没有以正确的方式响应全部...这是jsp表单:
<%@ 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类的一个片段:
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;
}
}
我很确定标签正是它应该的样子。请求正在正确发送,并且正在接收响应。这看起来像是 jquery 的问题......感谢您的帮助