wlq530
wlq530
2011-10-13 14:05

简单问题struts2标签显示不出来action里的数据

已采纳

UsersAction.java:
[code="java"]public String getAllUserInfo() throws Exception
{
list = userService.getAllUserInfo();
for(Users userInfo : list)
{
System.out.println(userInfo.getUsername());
}
setList(list);
return SUCCESS;
}[/code]

UserService.java:
[code="java"]public interface UserService {

public int insertUsers(Users users);
public List<Users> getAllUserInfo();

}[/code]

UserServiceImpl.java:[code="java"]public class UserServiceImpl implements UserService {

private DataDaoService baseDao;

public DataDaoService getBaseDao() {
    return baseDao;
}
public void setBaseDao(DataDaoService baseDao) {
    this.baseDao = baseDao;
}
public int insertUsers(Users users) {

    return baseDao.saveObject("insertUsers", users);
}
  public List<Users> getAllUserInfo(){
      return baseDao.getAllUserInfo();  
  }

}[/code]

DataDaoService.java:
[code="java"]public interface DataDaoService {

public int saveObject(String methodName,Object object);
public List<Users> getAllUserInfo();

}[/code]
DataDaoServiceimpl.java[code="java"]public class DataDaoServiceimpl extends SqlMapClientDaoSupport implements DataDaoService{

public int saveObject(String methodName,Object object)
{
    return (Integer)this.getSqlMapClientTemplate().insert(methodName,object);
}

@SuppressWarnings("unchecked")
public List<Users> getAllUserInfo() {
    // TODO Auto-generated method stub
    return getSqlMapClientTemplate().queryForList("selectAllUsers");    
}

}[/code]
Users.java:
[code="java"]public class Users {

private int id;
private String username;
private String userpass;
private String sex;
private int age;
private String remark;
public int getid() {
    return id;
}
public void setid(int id) {
    this.id = id;
}
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
public String getUserpass() {
    return userpass;
}
public void setUserpass(String userpass) {
    this.userpass = userpass;
}
public String getSex() {
    return sex;
}
public void setSex(String sex) {
    this.sex = sex;
}
public int getAge() {
    return age;
}
public void setAge(int age) {
    this.age = age;
}
public String getRemark() {
    return remark;
}
public void setRemark(String remark) {
    this.remark = remark;
}

}
[/code]
User.xml:

[code="java"]<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap

PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"

"http://ibatis.apache.org/dtd/sql-map-2.dtd">


<!-- Use type aliases to avoid typing the full classname every time. -->

<!-- Result maps describe the mapping between the columns returned
from a query, and the class properties. A result map isn't
necessary if the columns (or aliases) match to the properties
exactly. -->







<!-- Select with no parameters using the result map for Account class. -->

select * from Users

<!-- A simpler select example without the result map. Note the
aliases to match the properties of the target result class. -->

select id,username,userpass,sex,age,remark from Users where id = #id#

<!-- Insert example, using the Account parameter class -->

insert into Users (username,userpass,sex,age,remark)
values(#username#, #userpass#, #sex#, #age#, #remark#)

<!-- Update example, using the Account parameter class -->

update Users setusername = #username#,userpass = #userpass#, age = #age# where id = #id#

<!-- Delete example, using an integer as the parameter class -->

delete from Users where id = #id#

[/code]

index.jsp:
[code="java"]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">







/s:iterator


[/code]

struts-users.xml:
[code="java"]<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<!-- 让spring管理struts2 -->

<!-- 更改处理后缀 -->
<!--


/index.jsp
/reg.jsp
/404.html

-->

   <package name="default" extends="struts-default">
    <action name="UserAction" class="userAction" method="getAllUserInfo">
        <result name="success" >/index.jsp</result>
    </action>
</package>

[/code]

错误如下:type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoSuchMethodError: com.opensymphony.xwork2.util.ValueStack.findValue(Ljava/lang/String;Z)Ljava/lang/Object;
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)

root cause

javax.servlet.ServletException: java.lang.NoSuchMethodError: com.opensymphony.xwork2.util.ValueStack.findValue(Ljava/lang/String;Z)Ljava/lang/Object;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.index_jsp._jspService(index_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)

root cause

java.lang.NoSuchMethodError: com.opensymphony.xwork2.util.ValueStack.findValue(Ljava/lang/String;Z)Ljava/lang/Object;
org.apache.struts2.components.Component.findValue(Component.java:255)
org.apache.struts2.components.IteratorComponent.start(IteratorComponent.java:269)
org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
org.apache.jsp.index_jsp._jspx_meth_s_005fiterator_005f0(index_jsp.java:100)
org.apache.jsp.index_jsp._jspService(index_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

13条回答

  • AngelAndAngel AngelAndAngel 10年前

    [quote]java.lang.NoSuchMethodError: [/quote]
    那的确就是包出了问题,检查与struts2相关的包

    点赞 评论 复制链接分享
  • cs123456789dn 对java有感觉 10年前

    你的Action方法里面setlist(list)是什么意思
    你已经把数据存到LIST集合了下面就不用写了 然后JSP页面就像你这样写
    你的代码没有什么问题都是对的不知道你的包在网上搜索一下struts2的包吧
    你如果实在解决不了就把你工程发给我 我帮你调式下

    点赞 评论 复制链接分享
  • shuai45 shuai45 10年前

    javax.servlet.ServletException: java.lang.NoSuchMethodError: com.opensymphony.xwork2.util.ValueStack.findValue(Ljava/lang/String;Z)Ljava/lang/Object;

    点赞 评论 复制链接分享
  • aini3456 aini3456 10年前

    如果以上都没有错误,那就有可能是web。xml中配置问题了,你把web.xml改成
    [code="java"]


    struts2

    org.apache.struts2.dispatcher.FilterDispatcher



    struts2
    /*



    org.springframework.web.context.ContextLoaderListener

    [/code]

    点赞 评论 复制链接分享
  • aini3456 aini3456 10年前

    有没有多余的比如两个xwork

    点赞 评论 复制链接分享
  • aini3456 aini3456 10年前

    jar包的作用不一样的,你写数据库成功与struts也没有关系。你还是看看jar包对不对吧

    点赞 评论 复制链接分享
  • AngelAndAngel AngelAndAngel 10年前

    你不会没有xwork2.jar包吧。

    点赞 评论 复制链接分享
  • aini3456 aini3456 10年前

    如果有值,你查下是否有的jar冲突

    点赞 评论 复制链接分享
  • aini3456 aini3456 10年前

    你可以先在jsp页面上写 判断list是否有值

    点赞 评论 复制链接分享
  • AngelAndAngel AngelAndAngel 10年前

    你的list有get set方法吧。

    点赞 评论 复制链接分享
  • AngelAndAngel AngelAndAngel 10年前

    1,你是通过你的这个action来跳转到这个jsp的么?
    2,可以贴出web.xml

    点赞 评论 复制链接分享
  • aini3456 aini3456 10年前

    你把jsp 中的iterator标签的 id 去掉,改为
    [code="java"]



    /s:iterator [/code]

    点赞 评论 复制链接分享
  • AngelAndAngel AngelAndAngel 10年前

    action有数据?但是页面的标签没有是吗,假如是的话,贴出页面的代码看看。

    点赞 评论 复制链接分享

相关推荐