struts2 s:select中的list取action中list值问题
jsp代码<s:selectname="attend"list="@com.action.kechenganpaiAction@kechengSelect()"/>act...
jsp代码
<s:select name="attend" list="@com.action.kechenganpaiAction@kechengSelect()" />
action代码
public List kechengSelect()
{
String sql="from kecheng where del='no'" ;
List kechengList=kechengDAO.getHibernateTemplate().find(sql);
return kechengList;
}
出错信息:
五月 02, 2015 8:27:26 下午 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'attend': The requested list key '@com.action.kechenganpaiAction@kechengSelect()' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
at org.apache.struts2.components.Component.fieldError(Component.java:231)
at org.apache.struts2.components.Component.findValue(Component.java:293) 展开
<s:select name="attend" list="@com.action.kechenganpaiAction@kechengSelect()" />
action代码
public List kechengSelect()
{
String sql="from kecheng where del='no'" ;
List kechengList=kechengDAO.getHibernateTemplate().find(sql);
return kechengList;
}
出错信息:
五月 02, 2015 8:27:26 下午 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'attend': The requested list key '@com.action.kechenganpaiAction@kechengSelect()' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
at org.apache.struts2.components.Component.fieldError(Component.java:231)
at org.apache.struts2.components.Component.findValue(Component.java:293) 展开
2个回答
展开全部
首先,struts2进行权限验证是用拦截器做的
一个简单的登录拦截器示例如下:
package com.zdf.interceptor;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.zdf.entity.Admin;
@SuppressWarnings("serial")
public class LoginInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
Admin admin = (Admin)invocation.getInvocationContext().getSession().get("ADMIN");
if(admin!=null){
return invocation.invoke();
}else{
return Action.LOGIN;
}
}
}
一个简单的登录拦截器示例如下:
package com.zdf.interceptor;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.zdf.entity.Admin;
@SuppressWarnings("serial")
public class LoginInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
Admin admin = (Admin)invocation.getInvocationContext().getSession().get("ADMIN");
if(admin!=null){
return invocation.invoke();
}else{
return Action.LOGIN;
}
}
}
展开全部
你用了@表示你想调用类里的静态方法,所以解决办法为两步
1,启动struts2的静态方法调用,在struts.xml里添加一个属性<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
2,把你的方法改成静态
public static List kechengSelect()
{
String sql="from kecheng where del='no'" ;
List kechengList=kechengDAO.getHibernateTemplate().find(sql);
return kechengList;
}
1,启动struts2的静态方法调用,在struts.xml里添加一个属性<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
2,把你的方法改成静态
public static List kechengSelect()
{
String sql="from kecheng where del='no'" ;
List kechengList=kechengDAO.getHibernateTemplate().find(sql);
return kechengList;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询