Struts2jsp页面无法传值和跳转到Action,该怎么办?
错误页面:

出现这个情况怎么办?
index.jsp代码
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Struts Demo!</title>
</head>
<body>
<form action="login" method="post"> <!--如果使用<s:form>标签会报错 -->
用户名:<input type="text"name="userName" id="userName"><br>
密码:<input type="text"name="password" id="password"><br>
<input type="submit" value="登录">
</form>
</body>
</html>
struts.xml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="com.demo.loginAction">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
loginAction.java代码
package com.demo;
import com.opensymphony.xwork2.ActionSupport;
public class loginAction extends ActionSupport
{
private static final long serialVersionUID = 1L;
private String userName;
private String password;
private loginModel loginMsg;
public String execute() throws Exception{
loginMsg = new loginModel("登录成功!","登录失败!");
if(userName.equals("tong")&&password.equals("123456")) {
return "success";
}else {
return "error";
}
}
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;
}
public loginModel getLoginMsg() {
return loginMsg;
}
public void setLoginMsg(loginModel loginMsg) {
this.loginMsg = loginMsg;
}
}
web.xml 代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/lib/struts-tag.tld</taglib-location>
</taglib>
</jsp-config>
<display-name>strutsLoginDemo</display-name>
<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>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
</web-app>
文件目录结构:
