我有以下的JSP如何通過使用AJAX
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Get the best deal on Qnatas Partner credit cards</title>
<script type="text/javascript">
function doAjaxPost() {
// get the form values
var name = $(#name).val();
$.ajax({
type: "POST",
url: "/cardselector/mailAction.do", // this is my action call
data: "name=" + name,
success: function(response){
// we have the response
$('#info').html(response);
},
error: function(e){
alert('Error: ' + e);
}
});
}
</script>
</head>
<body>
<p>Welcome to card selector</p>
<html:form action="/cardsList" target="cardsListForm">
<html:text name="cardsListForm" property="message" maxlength="250"/>
<div id="name">sample</div>
<input type="text" id="name">myname</input>
<input type="button" value="Say Hello"><br/>
<div id="info" style="color: green;"></div>
</html:form>
</body>
</html>
,這是我的形式
import java.util.List;
import org.apache.struts.action.ActionForm;
public class CardsListForm extends ActionForm{
private static final long serialVersionUID = 1L;
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
這是值傳遞(這不是一個形式值)在struts 1.3行動我的行動
public class MailAction extends Action {
private CardManagementService cardManagementService;
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
try {
// Need to get the value of name from jsp input text
} catch (Exception e) {
System.out.println("Error:" + e.getMessage());
e.printStackTrace();
}
return mapping.findForward("success");
}
}
現在我想用一個按鈕的點擊阿賈克斯從JSP TP我的動作類通過MYNAME的價值。請注意這個名字不是我的表單類的一個屬性。
請問有沒有可能的幫助!
哪裏是在你的代碼AJAX? – Jai
我已經添加了Ajax功能在我的代碼 – nallskarthi