struts2调用Action的list方法时报错

regezetace 2011-06-08 11:42:27
直接访问,localhost/project/user,可以找到Action,并执行execute()方法;
现在想访问Action中的list()方法;
public String list() throws Exception {
return "list" ;
}

struts.xml
<package name="default" namespace="/" extends="struts-default">
<action name="user" class="com.ebusu.action.UserAction">
<result name="success">/success.jsp</result>
<result name="list">/list.jsp</result>
</action>
</package>

浏览器访问localhost/project/user!list会报错
-------------------
There is no Action mapped for namespace / and action name user!list.
-------------------

请问这是怎么回事?
...全文
90 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengyun817 2011-06-08
  • 打赏
  • 举报
回复
贴出com.ebusu.action.UserAction看看。
regezetace 2011-06-08
  • 打赏
  • 举报
回复
还是不行...
fengyun817 2011-06-08
  • 打赏
  • 举报
回复
struts.xml里指定如下内容:

<!-- 该属性指定需要Struts 2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都由Struts2 处理。 如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。 -->
<constant name="struts.action.extension" value="action"/>
regezetace 2011-06-08
  • 打赏
  • 举报
回复
我不知道怎么限定,反正加不加后缀.action,都报一样的错
regezetace 2011-06-08
  • 打赏
  • 举报
回复
嗯.action有个list方法,返回字符串"list",然后再xml中也配了result,再webRoot的根目录中也建好了list.jsp..
还有别的需要设置的地方吗
fengyun817 2011-06-08
  • 打赏
  • 举报
回复
你限定了后缀吧。 访问:localhost/project/user!list.action试试
wei_wxx 2011-06-08
  • 打赏
  • 举报
回复
确定你后面的action映射路径是对的?
fengyun817 2011-06-08
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 regezetace 的回复:]

不行啊`
我把其余的jar全清楚了,就用strut的他也给我报错
XML code

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.……
[/Quote]

把动态调用打开就行了。

<!-- 该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可设置该 属性为false。 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

regezetace 2011-06-08
  • 打赏
  • 举报
回复
不行啊`
我把其余的jar全清楚了,就用strut的他也给我报错

<?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">

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<package name="default" namespace="/" extends="struts-default">
<action name="user" class="com.test.action.UserAction">
<result name="success">/success.jsp</result>
<result name="list">/success.jsp</result>
<result name="test">/list.jsp</result>
</action>
</package>

<!-- Add packages here -->

</struts>

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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<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>

fengyun817 2011-06-08
  • 打赏
  • 举报
回复
我试验了下,没有问题啊。
你再试下:
我的xml:

<package name="default" namespace="/" extends="struts-default">
<action name="user" class="com.struts2.TestAction">
<result name="success" >/hello.jsp</result>
</action>
</package>


类:

public class FirstAction extends ActionSupport {

public String execute() throws Exception {
return "success";
}
public String list() throws Exception {
return "success";
}

}


jsp里只有个hello

访问:http://localhost:8088/struts2/user!list

可以显示hello
regezetace 2011-06-08
  • 打赏
  • 举报
回复
@Component("user")
@Scope("prototype")
public class UserAction extends ActionSupport implements ModelDriven
{
private UserDTO userDTO = new UserDTO();

public UserDTO getUserDTO() {
return userDTO;
}

public void setUserDTO(UserDTO userDTO) {
this.userDTO = userDTO;
}


private UserService us ;


public UserService getUs() {
return us;
}

@Resource(name="userService")
public void setUs(UserService us) {
this.us = us;
}

private List<User> users ;

public List<User> getUsers() {
return users;
}

public void setUsers(List<User> users) {
this.users = users;
}

public String execute() throws Exception{
System.out.println( us ) ;
User u = new User() ;
u.setName( userDTO.getName() ) ;
this.getUs().add( u ) ;
return SUCCESS ;
}

public String list() throws Exception {
System.out.println("list method!!!") ;
this.users = this.getUs().list() ;
return "list" ;
}

public String test() throws Exception {
return "test" ;
}

public Object getModel() {
return this.userDTO;
}
}

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧