s2sh分页时页数过多隐藏action怎麽写

你正在使用的浏览器版本过低,将不能正常浏览和使用知乎。s2sh中struts2的页面的值无法传的action中,相当头痛…… - ITeye问答
代码我给大家贴过来,希望大家多费心帮忙看看,谢谢了……===========================================[color=#FF0000]Things.java[/color]___________________________________________package com.lg.
import java.util.D
public class Things { private I private S private D private I private I private I private G private I public Integer getId() { } public void setId(Integer id) {
this.id = } public String getName() { } public void setName(String name) {
this.name = } public Date getDate() { } public void setDate(Date date) {
this.date = } public Integer getMoney() { } public void setMoney(Integer money) {
this.money = } public Integer getDvalue() { } public void setDvalue(Integer dvalue) {
this.dvalue = } public Integer getMvalue() { } public void setMvalue(Integer mvalue) {
this.mvalue = } public Group getGroup() { } public void setGroup(Group group) {
this.group = } public Integer getGid() { } public void setGid(Integer gid) {
this.gid = } }
[color=#FF0000]Things.hbm.xml[/color]__________________________________________________&?xml version="1.0"?&&!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" ""&&hibernate-mapping& &class name="com.lg.bean.Things" table="lg_things"&
&id name="id" type="java.lang.Integer" column="id"&
&generator class="increment"&&/generator&
&property name="name" type="java.lang.String" length="50" column="name" /&
&property name="date" type="java.util.Date" column="date" /&
&property name="money" type="java.lang.Integer" column="money" /&
&property name="dvalue" type="java.lang.Integer" column="dvalue" /&
&property name="mvalue" type="java.lang.Integer" column="mvalue" /&
&property name="gid" type="java.lang.Integer" column="gid" insert="false" update="false" /&
&many-to-one name="group" class="com.lg.bean.Group" fetch="select"&
&column name="gid" not-null="true" /&
&/many-to-one& &/class& &/hibernate-mapping&
[color=#FF0000]ThingsDao.java[/color]_____________________________________________________________package com.lg.
import java.util.L
import com.lg.bean.T
public interface ThingsDao {
* 保存一条记录
*/ public void save(Things thing) ; /**
* 更新一条记录
*/ public void update(Things thing) ; /**
* 删除一条记录
*/ public void delete(Integer id) ; /**
* 查询单条记录
*/ public Things find(Integer id) ; /**
* 查询所有记录
*/ public List&Things& findAll() ; /**
* 按条件查询记录
*/ public List&Things& pointFind(Object[] obj) ;}[color=#FF0000]ThingsDaoImpl.java[/color]_________________________________________________________package com.lg.dao.
import java.util.L
import org.springframework.orm.hibernate3.support.HibernateDaoS
import com.lg.bean.Timport com.lg.dao.ThingsD
public class ThingsDaoImpl extends HibernateDaoSupport implements ThingsDao {
public void delete(Integer id) {
this.getHibernateTemplate().delete(this.find(id)) ; }
public Things find(Integer id) {
return (Things) this.getHibernateTemplate().get(Things.class, id); }
@SuppressWarnings("unchecked") public List&Things& findAll() {
String hql = "from Things things order by things.date" ;
List&Things& list = this.getHibernateTemplate().find(hql) ; }
@SuppressWarnings("unchecked") public List&Things& pointFind(Object[] obj) {
String tj = "" ;
for(int i = 0 ; i&obj. i++){
tj += "and".toString()+obj[i].toString()+"=".toString()+obj[i+1] ;
String hql = "from Things things where 0=0"+
List&Things& list = this.getHibernateTemplate().find(hql) ; }
public void save(Things things) {
this.getHibernateTemplate().save(things) ; }
public void update(Things things) {
this.getHibernateTemplate().update(things) ; }
}[color=#FF0000]ThingsService.java[/color]____________________________________________________________package com.lg.
import java.util.L
import com.lg.bean.T
public interface ThingsService { /**
* 保存一条记录
*/ public void save(Things thing) ; /**
* 更新一条记录
*/ public void update(Things thing) ; /**
* 删除一条记录
*/ public void delete(Integer id) ; /**
* 查询单条记录
*/ public Things find(Integer id) ; /**
* 查询所有记录
*/ public List&Things& findAll() ; /**
* 按条件查询记录
*/ public List&Things& pointFind(Object[] obj) ;}ThingsServiceImpl.java________________________________________________________package com.lg.service.
import java.util.L
import com.lg.bean.Timport com.lg.dao.ThingsDimport com.lg.service.ThingsS
public class ThingsServiceImpl implements ThingsService { private ThingsDao thingsD public void setThingsDao(ThingsDao thingsDao) {
this.thingsDao = thingsD }
public void delete(Integer id) {
thingsDao.delete(id) ; }
public Things find(Integer id) {
return thingsDao.find(id); }
public List&Things& findAll() {
return thingsDao.findAll(); }
public List&Things& pointFind(Object[] obj) {
return thingsDao.pointFind(obj); }
public void save(Things thing) {
thingsDao.save(thing) ; }
public void update(Things thing) {
thingsDao.update(thing) ; }
}[color=#FF0000]ThingsAction.java[/color]_________________________________________________________package com.lg.
import java.util.M
import com.lg.bean.Gimport com.lg.bean.Timport com.lg.service.GroupSimport com.lg.service.ThingsSimport com.opensymphony.xwork2.ActionCimport com.opensymphony.xwork2.ActionS
@SuppressWarnings("serial")public class ThingsAction extends ActionSupport { private T private G private ThingsService thingsS private GroupService groupS public void setThings(Things things) {
System.out.println("in setThings");
this.things = } public Things getThings() {
System.out.println("in getThings"); } public void setThingsService(ThingsService thingsService) {
this.thingsService = thingsS }
public Group getGroup() { } public void setGroup(Group group) {
this.group = } public void setGroupService(GroupService groupService) {
this.groupService = groupS } @Override public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS; } public String save(){
System.out.println(things.getName());
System.out.println(things.getDate());
System.out.println(things.getMoney());
System.out.println(things.getMoney());
System.out.println(things.getGid());
System.out.println(things.getDvalue());
thingsService.save(things) ;
return SUCCESS ; } @SuppressWarnings("unchecked") public String forsave(){
Map request = (Map)ActionContext.getContext().get("request") ;
request.put("glist", groupService.getList()) ;
return SUCCESS ; }
public String update(){
thingsService.update(things) ;
return SUCCESS ; }
@SuppressWarnings("unchecked") public String findAll(){
Map request = (Map)ActionContext.getContext().get("request") ;
request.put("list", thingsService.findAll()) ;
return SUCCESS ; }
@SuppressWarnings("unchecked") public String find(){
Map request = (Map)ActionContext.getContext().get("request") ;
request.put("list", thingsService.find(things.getId())) ;
return SUCCESS ; }
public String delete(){
thingsService.delete(things.getId()) ;
return SUCCESS ; } }[color=#FF0000]UserValidateInterceptor.java[/color]________________________________________________________
package com.lg.
import java.util.M
import com.opensymphony.xwork2.Aimport com.opensymphony.xwork2.ActionIimport com.opensymphony.xwork2.interceptor.AbstractI
@SuppressWarnings("serial")public class UserValidateInterceptor extends AbstractInterceptor {
@SuppressWarnings("unchecked") public String intercept(ActionInvocation ai) throws Exception {
Map session = ai.getInvocationContext().getSession() ;
String result =
if(null!=session.get("user")){
result = ai.invoke() ;
result = Action.LOGIN ;
}[color=#FF0000]DateFormate.java[/color]_________________________________________________________package com.lg.
import java.util.D
public class DateFormate {
public static Date getDate(){
return new java.sql.Date((new Date()).getYear(),(new Date()).getMonth(),(new Date()).getDay()) ; }}
[color=#FF0000]struts.xml[/color]_______________________________________________________&?xml version="1.0" encoding="UTF-8" ?&
&!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
&struts& &package name="lvg" extends="struts-default"&
&interceptors&
&interceptor name="userValidateInterceptor" class="com.lg.interceptor.UserValidateInterceptor" /&
&/interceptors&
&global-results&
&result name="login" type="redirect"&/index.jsp&/result&
&/global-results&
&!-- User 相关的action --&
&action name="register" class="register"&
&result name="success" type="redirect"&/index.jsp&/result&
&result name="input"&/register.jsp&/result&
&action name="login" class="login"&
&result name="success" type="redirect"&/main.jsp&/result&
&result name="input"&/index.jsp&/result&
&!-- Group 相关的action --&
&action name="grouplist" class="group" method="getList"&
&result name="success"&/grouplist.jsp&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="deleteGroup" class="group" method="delete"&
&result name="success" type="redirect"&grouplist.action&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="updateGroup" class="group" method="getOne"&
&result name="success"&/update.jsp&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="update" class="group" method="update"&
&result name="success" type="redirect"&grouplist.action&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="saveGroup" class="group" method="save"&
&result name="success" type="redirect"&grouplist.action&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&!-- Things 相关的action --&
&action name="thingslist" class="things" method="findAll"&
&result name="success"&/thingslist.jsp&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="forsave" class="things" method="forsave"&
&result name="success"&/record.jsp&/result&
&result name="input"&thingslist.action&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="savethings" class="things" method="save"&
&result name="success" type="redirect"&thingslist.action&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="forupdatethings" class="things" method="find"&
&result name="success"&/update.jsp&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="updatethings" class="things" method="update"&
&result name="success" type="redirect"&thingslist.action&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="deletethings" class="things" method="delete"&
&result name="success" type="redirect"&thingslist.action&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&action name="detail" class="things" method="delete"&
&result name="success" type="redirect"&thingslist.action&/result&
&result name="input"&/main.jsp&/result&
&interceptor-ref name="userValidateInterceptor" /&
&interceptor-ref name="defaultStack" /&
&/package&&/struts&[color=#FF0000]applicationContext.xml[/color]_________________________________________________________-&?xml version="1.0" encoding="UTF-8"?&&beans xmlns="" xmlns:xsi="" xmlns:p="" xsi:schemaLocation=" "& &bean id="dataSource" class="mons.dbcp.BasicDataSource"&
&property name="driverClassName" value="com.mysql.jdbc.Driver"&&/property&
&property name="url" value="jdbc:mysql://localhost:3306/lg_data"&&/property&
&property name="username" value="root"&&/property&
&property name="password" value="root"&&/property&
&property name="maxActive" value="100"&&/property&&!-- 最大活动连接数 --&
&property name="maxIdle" value="30"&&/property&&!-- 最大可空闲的连接数 --&
&property name="maxWait" value="500"&&/property&&!-- 最大可以等待的连接数 --&
&property name="defaultAutoCommit" value="true"&&/property&&!-- 默认自动提交,true每执行完一次数据操作之后就自动提交,相当于没有事物--& &/bean& &bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&
&property name="dataSource" ref="dataSource"&&/property&
&property name="hibernateProperties"&
&prop key="hibernate.dialect"&org.hibernate.dialect.MySQLDialect&/prop&
&prop key="hibernate.show_sql"&true&/prop&
&/property&
&property name="mappingResources"&
&value&com/lg/bean/User.hbm.xml&/value&
&value&com/lg/bean/Group.hbm.xml&/value&
&value&com/lg/bean/Things.hbm.xml&/value&
&/property& &/bean& &!-- User 相关的bean --& &bean id="userDao" class="com.lg.dao.impl.UserDaoImpl" scope="prototype"&
&property name="sessionFactory"&
&ref bean="sessionFactory"/&
&/property& &/bean& &bean id="userService" class="com.lg.service.impl.UserServiceImpl" scope="prototype"&
&property name="userDao" ref="userDao"&&/property& &/bean&
&bean id="register" class="com.lg.action.RegisterAction" scope="prototype"&
&property name="userService" ref="userService"&&/property& &/bean&
&bean id="login" class="com.lg.action.LoginAction" scope="prototype"&
&property name="userService" ref="userService"&&/property& &/bean& &!-- Group 相关的bean --& &bean id="groupDao" class="com.lg.dao.impl.GroupDaoImpl" scope="prototype"&
&property name="sessionFactory"&
&ref bean="sessionFactory"/&
&/property& &/bean& &bean id="groupService" class="com.lg.service.impl.GroupServiceImpl" scope="prototype"&
&property name="groupDao" ref="groupDao"&&/property& &/bean& &bean id="group" class="com.lg.action.GroupAction" scope="prototype"&
&property name="groupService" ref="groupService"&&/property& &/bean& &!-- Things 相关的bean --& &bean id="thingsDao" class="com.lg.dao.impl.ThingsDaoImpl" scope="prototype"&
&property name="sessionFactory"&
&ref bean="sessionFactory" /&
&/property& &/bean& &bean id="thingsService" class="com.lg.service.impl.ThingsServiceImpl" scope="prototype"&
&property name="thingsDao" ref="thingsDao" /& &/bean& &bean id="things" class="com.lg.action.ThingsAction" scope="prototype"&
&property name="thingsService" ref="thingsService" /&
&property name="groupService" ref="groupService" /& &/bean&&/beans&
[color=#FF0000]record.jsp[/color]____________________________________________________________&%@ page language="java" import="java.util.*" pageEncoding="utf-8"%&&%@ taglib prefix="lg" uri="/struts-tags"%&
&!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&&html&
&title&V1.0&/title&
&link rel="stylesheet" type="text/css" href="style/class.css"&
&lg:label value="%{getText('add.things')}" cssClass="title"&&/lg:label&
&lg:form action="savethings" method="post"&
&lg:hidden name="things.mvalue" value="1"&&/lg:hidden&
&lg:textfield name="things.name" label="%{getText('name.things')}" id="name" cssClass="text"&&/lg:textfield&
&lg:textfield name="things.date" label="%{getText('date.things')}" id="date" cssClass="text"&&/lg:textfield&
&lg:textfield name="things.money" label="%{getText('money.things')}" id="money" cssClass="text"&&/lg:textfield&
&lg:select list="#{'0':'没用','1':'拿不定','2':'有用'}" label="%{getText('dayvalue.things')}" name="things.dvalue" cssClass="text" id="dvalue" /&
&lg:select list="#request.glist" listKey="gid" listValue="gname" label="%{getText('groupname')}" name="things.gid" cssClass="text" id="gid"&&/lg:select&
&lg:submit value="::%{getText('submit')}::" name="submit"&&/lg:submit&
&/lg:form&
&/body&&/html&
希望大家多帮忙看看,小弟先谢过了……
问题补充:&div class="quote_title"&lizhi92574 写道&/div&&div class="quote_div"&
&br /&没发现问题你是不是还少给了东西,struts.xml 不止这一个文件吧。
&br /&
&br /&都没看到
&br /&&pre name="code" class="java"&&constant name="struts.objectFactory" value="spring" /&&/pre&&/div&
&br /&似乎跟这个没有关系,因为其他dao.service,action都用的这个struts,那个objectFactory似乎在他默认的struts-default文件里边有,如果拿出来只不过是对他进行覆盖,跟这个似乎没有直接关系……
问题补充:&div class="quote_title"&enet_java 写道&/div&&div class="quote_div"&action中定义的
&br /&private T
&br /& private G
&br /&修改为
&br /&private Things things =new Things ();
&br /& private Group group =new Group ();
&br /&要不然获取时会抛出异常的。&/div&
&br /&&div class="quote_title"&enet_java 写道&/div&&div class="quote_div"&action中定义的
&br /&private T
&br /& private G
&br /&修改为
&br /&private Things things =new Things ();
&br /& private Group group =new Group ();
&br /&要不然获取时会抛出异常的。&/div&
&br /&的确是用new之后就可以了,但是为什么呢?
&br /&其他的都没有用new的……
采纳的答案
action中定义的
private T
private G
修改为
private Things things =new Things ();
private Group group =new Group ();
要不然获取时会抛出异常的。
默认不是spring,web.xml 配置发来看看。
没发现问题你是不是还少给了东西,struts.xml 不止这一个文件吧。
都没看到
&constant name="struts.objectFactory" value="spring" /&
已解决问题
未解决问题4282人阅读
前端(14)
上篇完成多选删除的功能之后,接下来就是做分页功能了。以前的分页是一个麻烦的问题。而且数据量巨大的时候,直接把这些元素取出来显然速度较慢,所以取一定区间的数据还是高效的。之前自己写分页的时候,分页的界面当然是自己做的,用了ejui之后,真的方便了很多。方便到什么程度了。&table id=&dg& title=&My Users& class=&easyui-datagrid&
style=&width: 700 height: 500px& url=&list_ej& toolbar=&#toolbar&
rownumbers=&true& fitColumns=&true&
这种写法也是可以的
&th field=&id& width=&50&&id&/th&
&th field=&name& width=&50&&name&/th&
&th field=&password& width=&50&&password&/th& --&
&th field=&ck& checkbox=&true&&&/th&
&th data-options=&field:'id',width:'200px'&&id&/th&
&th data-options=&field:'name',width:'200px'&&name&/th&
&th data-options=&field:'password',width:'200px',align:'right'&&password&/th&
&/table&只需要在属性里面添加:pagination=&true& pageNumber =&1&pagination是在底部显示分页工具栏,pageNumber是原始的显示的页数,第几页。难点在于后台数据要怎么传过去。在没和后台正确处理页数和每页显示的数据数的关系时,是全部显示的,但是选择页面数的时候ejui还是会正确地帮你跳到具体的页数。但这显然不是我们想要的。后面在思路上就卡住了,我要怎么将分页栏的数据传到action里面呢?解决办法是,直接由rows和page属性,分别对应一页显示的数据条数和当前页数,只需要在action里面声明为全局变量,并写出对应的get和set方法。public class ControlAction extends ActionSupport{
public int getRows() {
public void setRows(int rows) {
this.rows =
public int getPage() {
public void setPage(int page) {
this.page =
}拿到之后容易处理。我们可以写一个封装的方法将拿到的页数和条数,对数据库操作并转换为json串。public String list_ej(){
ActionContext ctx=ActionContext.getContext();
String result=&&;
result= PageUtil.getPage(page, rows);
ServletActionContext.getResponse().getWriter().println(JSONArray.fromObject(list));
ctx.put(&json&, result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return &success&;
}PageUtil.java
import java.sql.C
import java.sql.ResultS
import java.sql.SQLE
import java.sql.S
import java.util.ArrayL
import java.util.L
import net.sf.json.JSONA
import net.sf.json.JSONO
public class PageUtil {
public static String getPage(int pagenumber,int rows){
String result = &&;
int count = 0;
int number = 0;
Connection c = ConnectToSQL.getConn();
Statement st = ConnectToSQL.getSt(c);
List&User& list = new ArrayList&User&();
ResultSet countrs = st.executeQuery(&select count(*) from user&);
countrs.next();
//System.out.println(countrs.getInt(1));
count = countrs.getInt(1);
} catch (SQLException e1) {
e1.printStackTrace();
if(count%rows==0){
number =count/
number = count/rows+1;
//System.out.println(number);
int index = 0;
if(pagenumber-1&0){
index = (pagenumber-1)*rows-1;
ResultSet rs = st.executeQuery(&select * from user limit &+index+&,&+rows);
while(rs.next()){
User u = new User();
u.setId(rs.getInt(&userid&));
u.setName(rs.getString(&username&));
u.setPassword(rs.getString(&password&));
list.add(u);
} catch (SQLException e) {
e.printStackTrace();
//这个把list看成数组,用json格式输出
只是输出list
List&User& o
= JSONArray.fromObject(list);
//无需字符串拼接
//String result = &{\&total\&:&+count+&,\&rows\&:&+s+&}&;
//接下来的是吧整个对象转json格式
对象有两个属性 total和rows属性
而rows里面又是一个数组
JSONObject jo = new JSONObject();
jo.put(&total&, count);
jo.put(&rows&, list);
result = jo.toString();
}ejui和struts2好用在哪里呢,ejui只需要接受到全部的数据条数和当前页的数据就是rows:后面的json数据,它会自动填充到DataGrid中。{&total&:5,&rows&:[{&id&:1277,&name&:&df2&,&password&:&123&},
{&id&:1278,&name&:&45ty&,&password&:&123&},
{&id&:1279,&name&:&sdfy&,&password&:&123&},
{&id&:1280,&name&:&345356&,&password&:&p&},
{&id&:1281,&name&:&werwer&,&password&:&twer&}]}
而一旦ejui的rows和page改变,一旦你选择page和rows,是通过ajax将数据传递过去,然后DataGrid局部刷新。它有会把参数传递给url,而struts本身通过get和set方法定义这两个属性之后又能取到这两个值,所以非常方便。也非常强大,界面美观。这个简单的CRUD系统功能大体完成,但是显然自己在JSON和EasyUI的掌握方面还不熟悉。这个还是要多练练。项目github地址:将java代码和jsp页面代码分离,新建了分支version2.0。
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:931186次
积分:8403
积分:8403
排名:第2128名
原创:129篇
评论:468条
文章:19篇
阅读:56761
(2)(3)(3)(4)(1)(3)(2)(1)(1)(2)(4)(5)(1)(1)(7)(3)(3)(4)(8)(5)(16)(8)(3)(2)(2)(1)(2)(2)(1)(3)(3)(6)(5)(9)(9)(5)(1)(2)(1)(1)}

我要回帖

更多关于 excel打印时自动分页 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信