1:后台:
Date today=new Date();
String result = today;
this.setJsonValue(result);
使用的時候要再外面見一個jsonData.jsp 的頁面存儲json數據,
前台js:
function getToDay() {
var today = "";
if (window.ActiveXObject) {
obj = new ActiveXObject('Microsoft.XMLHTTP');
} else if (window.XMLHttpRequest) {
obj = new XMLHttpRequest();
}
var url = context + '/clocksynchronization/getSystemTime.action';
obj.open('GET', url, false);
obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
obj.send(null);
today = obj.responseText;
return today;
};
2:后台:
String jsonValue;
Date today=new Date();
SetJsonValue(”{success:true,time:’”+today+”’}”);
使用的時候要再外面見一個jsonData.jsp 的頁面存儲json數據
前台js:
function getToDay(response, opts) {
Ext.Ajax.request({
url : context +'/clocksynchronization/getSystemTime.action',
success : function(response, action) {
var result = Ext.util.JSON.decode(response.responseText);
if (result.success)
today=result.time;
else {
Ext.Msg.alert('提示', '请求失败!');
}
}
Return today;
}
3:通过request
后台:
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("叉叉", “xxxx”);
前台jsp:
<script type="text/javascript">
var context = '${pageContext.request.contextPath}';
var x = '<%=request.getAttribute("叉叉")%>';
</script>
js中调用:
var x = eval(x);
4:通过struts注入方式
后台:
public String userName;
get(){}
set(){}
前台jsp:
<input type = "hidden" id="name" value=" ${ userName } ">
前台js:
var name = Ext.get(‘name’).dom.value;
Date today=new Date();
String result = today;
this.setJsonValue(result);
使用的時候要再外面見一個jsonData.jsp 的頁面存儲json數據,
前台js:
function getToDay() {
var today = "";
if (window.ActiveXObject) {
obj = new ActiveXObject('Microsoft.XMLHTTP');
} else if (window.XMLHttpRequest) {
obj = new XMLHttpRequest();
}
var url = context + '/clocksynchronization/getSystemTime.action';
obj.open('GET', url, false);
obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
obj.send(null);
today = obj.responseText;
return today;
};
2:后台:
String jsonValue;
Date today=new Date();
SetJsonValue(”{success:true,time:’”+today+”’}”);
使用的時候要再外面見一個jsonData.jsp 的頁面存儲json數據
前台js:
function getToDay(response, opts) {
Ext.Ajax.request({
url : context +'/clocksynchronization/getSystemTime.action',
success : function(response, action) {
var result = Ext.util.JSON.decode(response.responseText);
if (result.success)
today=result.time;
else {
Ext.Msg.alert('提示', '请求失败!');
}
}
Return today;
}
3:通过request
后台:
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("叉叉", “xxxx”);
前台jsp:
<script type="text/javascript">
var context = '${pageContext.request.contextPath}';
var x = '<%=request.getAttribute("叉叉")%>';
</script>
js中调用:
var x = eval(x);
4:通过struts注入方式
后台:
public String userName;
get(){}
set(){}
前台jsp:
<input type = "hidden" id="name" value=" ${ userName } ">
前台js:
var name = Ext.get(‘name’).dom.value;