首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

struts2 注解有关问题

2014-01-19 
struts2 注解问题好久没用struts2了,今天用struts2零配置的时候出现下面的错误,百度好久都不知道问题出在

struts2 注解问题
好久没用struts2了,今天用struts2零配置的时候出现下面的错误,百度好久都不知道问题出在哪里,希望各位大牛帮我看看

2014-1-14 17:03:15 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Could not find action or result
There is no Action mapped for namespace /fanice/user and action name oss. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)


启动都不报错,访问action 的时候报错了

action
package com.mycommon.web.fanice.user;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

@Results( { @Result(name = "success", location = "index.jsp"),  
    @Result(name = "error", location = "index.jsp") })
@Action("oss")
public class UserAction extends ActionSupport  implements ModelDriven<Object>, Preparable{

private static final long serialVersionUID = 1L;

//
public String add(){
System.out.println("welcome struts2 !");
return "success";
}
@Override
public String execute(){
System.out.println("AAAAAAAA");
return SUCCESS;
}
@Override
public void prepare() throws Exception {}
@Override
public Object getModel() {
// TODO Auto-generated method stub
return null;
}
}


访问路径:http://localhost:8088/MyCommon/fanice/user/oss.action

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>
 <!--  指定默认的父包  --> 
  <constant name="struts.convention.default.parent.package" value="bolo-default" /> 
 <!--  设置convention插件默认的根包 --> 
  <constant name="struts.convention.package.locators" value="web" /> 


  <constant name="struts.convention.result.path" value="/WEB-INF/page" /> 
 <!--  搜索此配置下的所有包  --> 
  <constant name="struts.convention.package.locators.basePackage" value="com.mycommon" /> 
<!--  继承convention-default包,定义一个默认的拦截器,根据需要还可扩展   --> 
<package name="bolo-default" extends="convention-default">
<interceptors>
<interceptor-stack name="boloStack">
  <interceptor-ref name="paramsPrepareParamsStack" /> 
  </interceptor-stack>
</interceptors>
<default-interceptor-ref name="boloStack" /> 
 </package>
  </struts>


[解决办法]
Action

@Namespace("/fanice/user") 
@Results( { @Result(name = "success", location = "/index.jsp"), 
@Result(name = "error", location = "/index.jsp") })
@Action("oss")
public class RegistAction extends ActionSupport {

/**
 * 
 */
private static final long serialVersionUID = 1L;

public String execute() {
System.out.println("Welcome to Annotation");
return SUCCESS;
}
}


struts.xml 为空
web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>struts2</display-name>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
   <init-param>   
<param-name>actionPackages</param-name>  
<param-value>com.zhangqi.action.RegistAction</param-value>  
</init-param> 
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>
web.xml中需要扫描配置action的包,楼主的里面配一堆spring的东东,不太熟悉
然后就是 webRoot下面的index.jsp了
可以成功访问。
建议楼主将web.xml简化下,先让程序跑起来,再添加监听等等。

热点排行