求解,struts2
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">
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts" extends="struts-default" namespace="/">
<action name="login" class="MVC.Login" method='loginx'>
<result name="SUCCESS">/success.jsp</result>
<result name="ERROR">/fail.jsp</result>
</action>
</package>
</struts>
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="MVC.Login"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<form action="./login" method="post">
<input type="text" name="id" >
<input type="password" name="pwd">
<input type="submit" value="登录" >
</form>
</body>
</html>
success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>成功</title>
</head>
<body>
<%
String id=request.getParameter("usm");
out.print("用户"+id+"登录成功");
%>
</body>
</html>
Login.java
package MVC;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport {
public String loginx(){
if ("good".equals(id) && "123".equals(pwd)) {
System.out.print("success");
return "SUCCESS";
}else {
System.out.print("fail");
return "ERROR";
}
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
private String id;
private String pwd;
}

