14 个解决方案
#1
你先把数据放到request中, 然后 jsp标签取数据。。
#2
这样如果数据量很大,存储很多个list。总感觉很麻烦,难道没有其他办法吗?
#3
数据大分页显示。 懒加载等等。
#4
#5
楼主,我想说,你还是先搞明白基本概念吧,什么是SSH,什么是List,什么是Ajax...基础很重要...
#6
但从技术角度来说应该说两种都有 因为 这两种针对的都是不同情况的。
要从性能上来说 可能更多会考虑一些成熟的框架 利用缓存 线程池等等
要从性能上来说 可能更多会考虑一些成熟的框架 利用缓存 线程池等等
#7
这个问题也太抽象了
#8
都可以 对于大型的比较规范的就用ssh架构吧 一般玩玩就用ajax简洁
#9
我学的时候是用s标签。。。直接遍历list
#10
AJAX用的多,会影响页面加载速度吗?
#11
现在的Struts2框架怎么还有建议用request的? 对于list后台一个get()和一个set()方法,前台直接展示就可以了,给你个例子:
1.action后台
2.前台直接展示:
1.action后台
public List<?> list;
public List<?> getList() {
return list;
}
public void setList(List<?> list) {
this.list = list;
}
list = this.UserService.execSQLQuery(sql);
2.前台直接展示:
<s:iterator value="#request.list" id="str" >
<s:property value="#str[0]"/>
<s:property value="#str[1]"/>
</s:iterator>
#12
怎么还有用struts2 标签进行页面展示数据的呢,下面给个列子struts 搭配 json ajax。代替struts2标签。实现数据内容局部刷新。
<script type="text/javascript">
var currentPage=1; //当前第1页
var pageSize = 7; //每页7条数据
$(document).ready(function(){
getNewsData();
})
function getNewsData(){
$.ajax({
url:'listInfoAjax.action', //进入页面执行listInfoAjax action
data:'currentPage='+currentPage, //参数 当前页,默认为1
type:'post',
dataType:'json', //使用接送格式。
// json格式的struts配置为
//<package name="...." extends="json-default" >
// <action name="..." class="..." method="..." >
<result type="json"></result>
// </action>
//</package>
success:function(data){ //回调函数,如果后台方法没有抛异常,执行下面的语句块。
// totalCount ,pageSize,infos,后台方法里变量
totalCount=data.totalCount; //总记录数
totalPage=data.pageSize; //总页数
var inf=data.infos; //集合
$("#deleteall").empty(); //清空页面数据源
var html=""; 即将要插入的数据
$.each(inf,function(i,news){ //相当于for循环
//需要展示的内容,如id,title,date
var id=news.id;
var title=news.title;
var date=news.date;
html+="<tr><td><input type='checkbox' style='background: #f4f4f4;border: 0px;' value='"+id+"'></td> <td>"+date+"</td><td>"+title+"</td> </tr>" //插入的数据
})
$(html).appendTo("#deleteall"); 数据插入到deleteall里面
$("#crt").empty(); //清空当前页字符串
$("#crt").append(currentPage); //改变当前页字符串
$(".fenye1").unbind(); // 给上一页,下一页,解除bind
$("#deleteall tr").css("background","#e5e5e5"); //给数据添加样式
$("#deleteall tr").mouseover(function(){
$(this).css("background","#FFFFCC").siblings().css("background","#e5e5e5");//同上
})
//改变上一页,下一页,样式。以及传入的样式。
if(totalPage!=1){
if(currentPage==1){
$("#pre").replaceWith("<b style='font-weight:normal;color:#eeeeee;' id='syy'>上一页</b>");
$("#next").click(function(){
changeCurrentPage($(this).attr("id"));
});
}else if(currentPage==totalPage){
$("#next").replaceWith("<b style='font-weight:normal;color:#eeeeee;' id='xyy'>下一页</b>");
$("#pre").click(function(){
changeCurrentPage($(this).attr("id"));
});
}else{
$("#syy").replaceWith("<a id='pre' class='fenye1' href='#'>上一页</a>");
$("#xyy").replaceWith("<a id='next' class='fenye1' href='#'>下一页</a>");
$(".fenye1").click(function(){
changeCurrentPage($(this).attr("id"));
});
}
}
}
});
}
function changeCurrentPage(id){
if(id=="pre") currentPage -= 1;
else if(id=="next") currentPage += 1;
else currentPage = id;
getNewsData();
}
</script>
#13
action返回到jsp后,如果传过来一个list的话 就可以用<s:iterator value="#list"> </s:iterator>这个迭代出来。
#14
struts有个值栈模型,不同的数据放在什么地方以及怎么取值。。
#1
你先把数据放到request中, 然后 jsp标签取数据。。
#2
这样如果数据量很大,存储很多个list。总感觉很麻烦,难道没有其他办法吗?
#3
数据大分页显示。 懒加载等等。
#4
#5
楼主,我想说,你还是先搞明白基本概念吧,什么是SSH,什么是List,什么是Ajax...基础很重要...
#6
但从技术角度来说应该说两种都有 因为 这两种针对的都是不同情况的。
要从性能上来说 可能更多会考虑一些成熟的框架 利用缓存 线程池等等
要从性能上来说 可能更多会考虑一些成熟的框架 利用缓存 线程池等等
#7
这个问题也太抽象了
#8
都可以 对于大型的比较规范的就用ssh架构吧 一般玩玩就用ajax简洁
#9
我学的时候是用s标签。。。直接遍历list
#10
AJAX用的多,会影响页面加载速度吗?
#11
现在的Struts2框架怎么还有建议用request的? 对于list后台一个get()和一个set()方法,前台直接展示就可以了,给你个例子:
1.action后台
2.前台直接展示:
1.action后台
public List<?> list;
public List<?> getList() {
return list;
}
public void setList(List<?> list) {
this.list = list;
}
list = this.UserService.execSQLQuery(sql);
2.前台直接展示:
<s:iterator value="#request.list" id="str" >
<s:property value="#str[0]"/>
<s:property value="#str[1]"/>
</s:iterator>
#12
怎么还有用struts2 标签进行页面展示数据的呢,下面给个列子struts 搭配 json ajax。代替struts2标签。实现数据内容局部刷新。
<script type="text/javascript">
var currentPage=1; //当前第1页
var pageSize = 7; //每页7条数据
$(document).ready(function(){
getNewsData();
})
function getNewsData(){
$.ajax({
url:'listInfoAjax.action', //进入页面执行listInfoAjax action
data:'currentPage='+currentPage, //参数 当前页,默认为1
type:'post',
dataType:'json', //使用接送格式。
// json格式的struts配置为
//<package name="...." extends="json-default" >
// <action name="..." class="..." method="..." >
<result type="json"></result>
// </action>
//</package>
success:function(data){ //回调函数,如果后台方法没有抛异常,执行下面的语句块。
// totalCount ,pageSize,infos,后台方法里变量
totalCount=data.totalCount; //总记录数
totalPage=data.pageSize; //总页数
var inf=data.infos; //集合
$("#deleteall").empty(); //清空页面数据源
var html=""; 即将要插入的数据
$.each(inf,function(i,news){ //相当于for循环
//需要展示的内容,如id,title,date
var id=news.id;
var title=news.title;
var date=news.date;
html+="<tr><td><input type='checkbox' style='background: #f4f4f4;border: 0px;' value='"+id+"'></td> <td>"+date+"</td><td>"+title+"</td> </tr>" //插入的数据
})
$(html).appendTo("#deleteall"); 数据插入到deleteall里面
$("#crt").empty(); //清空当前页字符串
$("#crt").append(currentPage); //改变当前页字符串
$(".fenye1").unbind(); // 给上一页,下一页,解除bind
$("#deleteall tr").css("background","#e5e5e5"); //给数据添加样式
$("#deleteall tr").mouseover(function(){
$(this).css("background","#FFFFCC").siblings().css("background","#e5e5e5");//同上
})
//改变上一页,下一页,样式。以及传入的样式。
if(totalPage!=1){
if(currentPage==1){
$("#pre").replaceWith("<b style='font-weight:normal;color:#eeeeee;' id='syy'>上一页</b>");
$("#next").click(function(){
changeCurrentPage($(this).attr("id"));
});
}else if(currentPage==totalPage){
$("#next").replaceWith("<b style='font-weight:normal;color:#eeeeee;' id='xyy'>下一页</b>");
$("#pre").click(function(){
changeCurrentPage($(this).attr("id"));
});
}else{
$("#syy").replaceWith("<a id='pre' class='fenye1' href='#'>上一页</a>");
$("#xyy").replaceWith("<a id='next' class='fenye1' href='#'>下一页</a>");
$(".fenye1").click(function(){
changeCurrentPage($(this).attr("id"));
});
}
}
}
});
}
function changeCurrentPage(id){
if(id=="pre") currentPage -= 1;
else if(id=="next") currentPage += 1;
else currentPage = id;
getNewsData();
}
</script>
#13
action返回到jsp后,如果传过来一个list的话 就可以用<s:iterator value="#list"> </s:iterator>这个迭代出来。
#14
struts有个值栈模型,不同的数据放在什么地方以及怎么取值。。