There is no Action mapped for namespace / and action name LoginAction. 一定要修改jdk1.8到1.6 写错了一个大小写 不要修改项目名,因为好像有个URL路径也要修改
看到这个地方,是表单的action找不到LoginAction.
<!--.action这一定要吗,为什么会有这个后缀 LoginAction.action错误原因这个地方写成大写L--> <form action="<%=path %>/loginAction.action" method="post"> 用户名:<input type="text" name="username" ><br> 密码:<input type="password" name="password" ><br> <input type="submit" value="提交"> </form>
错误的原因是我写错了.
之前我还在想为什么会有action 的后缀,其实这个action的后缀是为了 跳到struts.xml.
<package name="userlogin" extends="struts-default" namespace=""> <action name="loginAction" class="com.jike.action.LoginAction"> <!-- 最后写一下这个action的返回页面 --> <result name="success">/index.jsp</result> </action> </package>
其实表单的action 是跳到这个的配置文件中的 action标签的name, 而不是直接跳转到LoginAction类,而是经由这个配置文件,然后再跳转到LoginAction类.
@SuppressWarnings("serial") public class LoginAction extends ActionSupport{ private String username; private String password; @Override public String execute() throws Exception { System.out.println(username); return "success"; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
跳转到这个
LoginAction 类之后,便执行execute()方法,然后返回return "success";到配置文件, 然后配置文件接收执行<result name="success">/index.jsp</result>,跳转到/index.jsp页面
public String execute() throws Exception { System.out.println(username); return "success"; }
孜孜不倦,必能求索;风尘仆仆,终有归途。