67,515
社区成员
发帖
与我相关
我的任务
分享
package login;
public class User {
// 创建变量 username和password,跟login.jsp页面里面的要保持一致
private String username;
private String password;
// 创建变量后要使用get和set函数,在其他类就可以使用set和get函数进行调用
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 String execute() {
return "success";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<include file="struts-default.xml"></include>
<!-- 指定默认编码集 -->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<!-- 指定需要Struts2处理的请求后缀 -->
<!-- <constant name="struts.action.extension" value="do,action"></constant> -->
<!-- 设置浏览器是否缓存静态内容,开发阶段应关闭,生产阶段打开,默认为打开 -->
<constant name="struts.serve.static.browserCache" value="false"></constant>
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认为false,开发阶段应打开 -->
<constant name="struts.configuration.xml.reload" value="true"></constant>
<!-- 开发模式下使用,可以打印出更详细的错误信息 -->
<constant name="struts.devMode" value="true"></constant>
<!-- action全部用注解进行配置 -->
<!-- 是否开启动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<!--添加包 -->
<package name="User" namespace="/" extends="struts-default">
<action name="login" class="login.User" method="User">
<result name="success">/result.jsp</result>
</action>
</package>
</struts>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head>
<body>
<!--定义用户,账号是username,密码是password -->
<form action="login">
账号:<input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
<input type="submit" name="submit" value="登录">
<input type="reset" value="重置" >
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'result.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
username:${requestScope.username } <br>
password:${requestScope.password }
</body>
</html>
<?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">
<display-name>login</display-name>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<include file="struts-default.xml"></include>
<!-- 指定默认编码集 -->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<!-- 指定需要Struts2处理的请求后缀 -->
<constant name="struts.action.extension" value="do,action"></constant>
<!-- 设置浏览器是否缓存静态内容,开发阶段应关闭,生产阶段打开,默认为打开 -->
<constant name="struts.serve.static.browserCache" value="false"></constant>
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认为false,开发阶段应打开 -->
<constant name="struts.configuration.xml.reload" value="true"></constant>
<!-- 开发模式下使用,可以打印出更详细的错误信息 -->
<constant name="struts.devMode" value="true"></constant>
<!-- action全部用注解进行配置 -->
<!-- 是否开启动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<!--添加包 -->
<package name="User" namespace="/" extends="struts-default" strict-method-invocation="false">
<action name="login" class="login.User" method="execute">
<result name="success">/result.jsp</result>
</action>
</package>
</struts>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head>
<body>
<!--定义用户,账号是username,密码是password -->
<form action="login.action">
账号:<input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
<input type="submit" name="submit" value="登录">
<input type="reset" value="重置" >
</form>
</body>
</html>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<include file="struts-default.xml"></include>
<!-- 指定默认编码集 -->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<!-- 指定需要Struts2处理的请求后缀 -->
<constant name="struts.action.extension" value="do,action"></constant>
<!-- 设置浏览器是否缓存静态内容,开发阶段应关闭,生产阶段打开,默认为打开 -->
<constant name="struts.serve.static.browserCache" value="false"></constant>
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认为false,开发阶段应打开 -->
<constant name="struts.configuration.xml.reload" value="true"></constant>
<!-- 开发模式下使用,可以打印出更详细的错误信息 -->
<constant name="struts.devMode" value="true"></constant>
<!-- action全部用注解进行配置 -->
<!-- 是否开启动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<!--添加包 -->
<package name="User" namespace="/" extends="struts-default">
<action name="login" class="login.User" method="execute">
<result name="success">/result.jsp</result>
</action>
</package>
</struts>