{
//得到文本框值
var description=document.getElementById("discriptionexpense1");
//局部請求地址
var url ="addexpenseand.action?description="+description.value;
//使用prototype函數構造xmlhttprequest對象
var myAjax = new Ajax.Request(
url,
{
//請求方法爲post
method:'post',
//設置參數爲 string=string
parameters:"string="+string,
//設置回調函數
onComplete:showResponse6,
//是否異步
asynchronous:true
}
);
}
function showResponse6(xmlrequest){
//回調函數
var text = xmlrequest.responseText;
document.getElementById("formdiv").innerHTML=text;
//將匹配的內容輸出到 span 層
//$("formdiv").innerHTML=xmlrequest.responseText;
// document.location.reload();
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<input name="discriptionexpense" id="discriptionexpense" type="text" />
<div id="formdiv">
</div>
<input type='button' name='button' id="buttonadd" value='Add' onClick="ok('add')"/>
</body>
</html>
相當鬱悶,無賴下只好repuest取值,依然亂碼。。。。
具體代碼:
private String string= null;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getString() {
return string;
}
public void setString(String string) {
this.string= string;
}
public void addexpenseand(){
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
String string1 = request.getParameter("string");//從JSP頁面拿值
String description1= request.getParameter("description");//從JSP頁面拿值
System.out.println(description );
System.out.println(string);
System.out.println(description1);
System.out.println(string1);
}
請各位高手發表發表高見。。。