action 里能取到数据,jtest 测试有数据的,dao 那里数据能打印到。
jsp里面用struts2标签显示不出来, 就一个白白的页面, 后台没有报错。在dao 那端打印也没有打到,
应该是 action 没有映射成功吗 ?
这个问题困扰我一天了。而且我把别人成功的例子拷到我这里,也是这种情况。
是不是因为我用的tomcat7版本过高? jar包引用的都是老的struts2.0和spring2.5那个时间的
代码贴一下:
[userlist.jsp]:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<body>
<s:iterator value="users">
<s:property value="username"/>
</s:iterator>
<s:debug></s:debug>
</body>
</html>
[web.xml]
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<!-- default: /WEB-INF/applicationContext.xml -->
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
[struts.xml]
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="registration" extends="struts-default">
<action name="user" class="com.bjsxt.registration.action.UserAction">
<result name="success">/registerSuccess.jsp</result>
<result name="fail">/registerFail.jsp</result>
<result name="list">/userlist.jsp</result>
</action>
</package>
</struts>
[userAtion.java]
package com.bjsxt.registration.action;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.bjsxt.registration.model.User;
import com.bjsxt.registration.service.UserManager;
import com.bjsxt.registration.vo.UserRegisterInfo;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Component("user")
@Scope("prototype")
public class UserAction extends ActionSupport implements ModelDriven {
private UserRegisterInfo info = new UserRegisterInfo();
private UserManager um;
private List<User> users;
public UserManager getUm() {
return um;
}
@Resource(name="userManager")
public void setUm(UserManager um) {
this.um = um;
}
@Override
public String execute() throws Exception {
User u = new User();
u.setUsername(info.getUsername());
u.setPassword(info.getPassword());