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.