web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="struts2" namespace="/" extends="struts-default">
<action name="login" class="com.test.Action.LoginAction" method="execute">
<result name="success">/welcome.jsp</result>
<result name="login">/login.jsp</result>
</action>
</package>
</struts>
LoginAction.java
package com.test.Action;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private String username;
private String password;
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() throws Exception{
if("haha".equals(username) && "hehe".equals(password))
return SUCCESS;
else return LOGIN;
}
}
两个jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login</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>
<s:form action="/login" method="post">
<s:label value="系统登陆"></s:label>
<s:textfield name="username" label="账号" />
<s:password name="password" label="密码" />
<s:submit value="登录" />
</s:form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'welcome.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 }!
</body>
</html>
- 大小: 37.6 KB
分享到:
相关推荐
struts2 配置dtd 自动提示 struts2 配置dtd 自动提示
struts2配置过滤器 示例代码
Struts2配置详解,Struts2配置详解,Struts2配置详解,Struts2配置详解,Struts2配置详解
struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置...
SSH笔记 Struts2配置 demo , 包含随时用的struts2 jar 和简单的配置
struts2配置文件 struts2代码
struts2配置文件加载顺序
·Struts2配置文件介绍 struts.xml action package ·Struts2配置文件介绍 struts.xml action package
struts2 配置SSH 或者简单的JSP文件 里面含有丰富的jar文件
配置SSH框架时关于Struts2的配置文件
struts2配置文件说明,详细说明了怎么配置文件
struts2配置MSSQL连接 <property name="driverClassName"><value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value></property> <property name="url"><value>jdbc:sqlserver://192.168.1.102:1433;...
Struts2配置
一个关于struts2配置详解,熟练这个配置可以让你自由配置struts2配置
Struts2配置及使用,你有用的斯蒂芬森的
struts2配置文件传值中文乱码
struts2配置文件介绍struts2配置文件介绍struts2配置文件介绍
struts2配置带中文解释 struts2配置带中文解释struts2配置带中文解释struts2配置带中文解释struts2配置带中文解释struts2配置带中文解释struts2配置带中文解释
Struts2 配置文件手册,Struts2 配置文件手册,Struts2 配置文件手册
NULL 博文链接:https://liubey.iteye.com/blog/703144