idea
maven
struts2.5+spring4.3.5+Hibernate5
通过注解开发,在jsp页面找不到action 404

Struts Problem Report
Struts has detected an unhandled exception:
Messages:
There is no Action mapped for namespace [/] and action name [addUser] associated with context path [].
Stacktraces
There is no Action mapped for namespace [/] and action name [addUser] associated with context path []. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:192)
org.apache.struts2.factory.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.factory.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:554)
org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:143)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:
struts.devMode=false
in your WEB-INF/classes/struts.properties file.

index.jsp
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:Spring.xml
struts2
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
filterConfig
classpath:struts.xml
actionPackages
com.ssh
struts2
/*
org.hibernate.dialect.MySQLDialect
update
true
true
false
package com.lab.action;
import com.lab.entity.User;
import com.lab.service.UserManager;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import javax.annotation.Resource;
/**
* Created by young on 2017/6/17.
*/
@Results({@Result(name = "success", location = "/success.jsp"),
@Result(name = "failure", location = "/failure.jsp")})
public class UserAction extends ActionSupport {
@Resource
private UserManager userManager;
private User user;
@Action(value = "addUser")
public String addUser() {
try {
userManager.addUser(user);
} catch (Exception e) {
e.printStackTrace();
return "failure";
}
return "success";
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
主要是参考 基于注解的SSH将配置精简到极致
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
UserAction类加 @Namespace("/")