搭建一个简单struts2框架的登陆
第一步:下载struts2对应的jar包,可以到struts官网下载:http://struts.apache.org/download.cgi#struts252
出于学习的目的,可以把整个完整的压缩文件都下载下来。
里面包括:1 apps:示例应用,对学习很有帮助 ; 2 docs:相关学习文档、API文档等; 3 lib:核心类库,依赖包; 4:src:源代码
第二步:在eclipse新建一个Dynamic Web Project类型工程,一直点next,记得勾选generate web.xml deployment descriptor,才能有web.xml
第三步:导入jar包
struts2有个几个必备的jar包,可以去官网下载struts-min-lib.zip,里面的包就是必须要的jar包。
第四步:编写对应的Action
在src下面新建一个包com.struts.action(注意:命名需要时com.XXX.action的形式),然后再下面新建一个java文件:LoginAction.java
package com.struts.action; import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
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("username".equals(this.getUsername()) && "password".equals(this.getPassword()))
{
return "success";
}
else
{
return "fail";
} }
}
第五步:新建结果页面
在WEB-INF新建下面两个文件:
success.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>success!</title>
</head>
<body>
success!
</body>
</html>
fail.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>fail!</title>
</head>
<body>
fail!
</body>
</html>
第六步:在WEB-INF下新建初始页面(根据LoginAction知道需要提交的表单里面有两个参数)
login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="login" method="post">
用户名:<input type="text" name="username">
密码:<input type="password" name="password">
<input type="submit" value="提交">
</form>
</body>
</html>
第七步:配置在WEB-INF下的web.xml:1、加入struts过滤器 2、配置首页
<?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>struts2Project</display-name>
<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>/WEB-INF/login.html</welcome-file>
</welcome-file-list>
</web-app>
第八步:配置struts2配置文件,在src目录下新建struts.xml,进行action配置
<?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"> <!-- START SNIPPET: xworkSample -->
<struts>
<package name="com.struts.action" extends="struts-default">
<action name="login" class="com.struts.action.LoginAction">
<result name="success">/WEB-INF/success.jsp</result>
<result name="fail">/WEB-INF/fail.jsp</result>
</action>
</package>
</struts>
结尾:至此完成简单struts2框架的登陆搭建,放进tomcat并启动,就可以通过http://localhost:8080/struts2Project/ 访问。
搭建一个简单struts2框架的登陆的更多相关文章
- vue+vux-ui+axios+mock搭建一个简单vue框架
1.首先感谢同事 2.之前一直在做angularjs的项目,目前vue火热,所以自己搭建了一个的vue框架,在此作为记录 vue+vux-ui这里就不介绍了,有很多博客都写的很详细了. 下面简单记录下 ...
- Prism for WPF 搭建一个简单的模块化开发框架(一)
原文:Prism for WPF 搭建一个简单的模块化开发框架(一) 最近闲来无事又想搞搞WPF..... 做个框架吧,可能又是半途而废....总是坚持不下来 不废话了, 先看一下工程结构 布局大概是 ...
- 用express搭建一个简单的博客系统
转自:https://blog.csdn.net/qq_29721837/article/details/62055603 Express 简介 Express 是一个简洁而灵活的 node.js W ...
- 【netty】(2)---搭建一个简单服务器
netty(2)---搭建一个简单服务器 说明:本篇博客是基于学习慕课网有关视频教学.效果:当用户访问:localhost:8088 后 服务器返回 "hello netty"; ...
- Prism for WPF 搭建一个简单的模块化开发框架(四)异步调用WCF服务、WCF消息头添加安全验证Token
原文:Prism for WPF 搭建一个简单的模块化开发框架(四)异步调用WCF服务.WCF消息头添加安全验证Token 为什么选择wcf? 因为好像wcf和wpf就是哥俩,,, 为什么选择异步 ...
- Prism for WPF 搭建一个简单的模块化开发框架(三) 给TreeView加样式做成菜单
原文:Prism for WPF 搭建一个简单的模块化开发框架(三) 给TreeView加样式做成菜单 昨天晚上把TreeView的样式做了一下,今天给TreeView绑了数据,实现了切换页面功能 上 ...
- Prism for WPF 搭建一个简单的模块化开发框架(二)
原文:Prism for WPF 搭建一个简单的模块化开发框架(二) 今天又有时间了,再改改,加了一些控件全局的样式 样式代码 <ResourceDictionary xmlns="h ...
- 【转】使用webmagic搭建一个简单的爬虫
[转]使用webmagic搭建一个简单的爬虫 刚刚接触爬虫,听说webmagic很不错,于是就了解了一下. webmagic的是一个无须配置.便于二次开发的爬虫框架,它提供简单灵活的API,只需少量代 ...
- 超详细,新手都能看懂 !使用SpringBoot+Dubbo 搭建一个简单的分布式服务
来自:JavaGuide Github 地址:https://github.com/Snailclimb/springboot-integration-examples 目录: 使用 SpringBo ...
随机推荐
- java程序设计线程池(newCachedThreadPool())
创建一个无界的可缓存的线程池,若线程长时间没用会自动销毁,直接上代码好了: import java.util.concurrent.ExecutorService; import java.util. ...
- Spring知识点提炼
原文出处: 朱小厮 1. Spring框架的作用 轻量:Spring是轻量级的,基本的版本大小为2MB 控制反转:Spring通过控制反转实现了松散耦合,对象们给出它们的依赖,而不是创建或查找依赖的对 ...
- jQuery初学:find()方法及children方法的区别分析
首先看看英文解释吧: children方法: find方法: 通过以上的解释,可以总结如下: 1:children及find方法都用是用来获得element的子elements的,两者都不会返回 te ...
- 超棒的javascript移动触摸设备开发类库-QUOjs
开发手机端网站.少不了手势事件? 手势事件怎么写? 手势事件怎么去判断? 对于新手来说.真的很Dan碎! 下面为大家推荐一款插件QUOjs 官方网站http://quojs.tapquo.com/ 这 ...
- SQL Left Join, Right Join, Inner Join, and Natural Join 各种Join小结
在SQL语言中,存在着各种Join,有Left Join, Right Join, Inner Join, and Natural Join等,对于初学者来说肯定一头雾水,都是神马跟神马啊,它们之间到 ...
- Oracle 实验四-七
shutdown immediateORA-01097: 无法在事务处理过程中关闭 - 请首先提交或回退 解决:先 "commit" 实验四 SQL Production :: C ...
- Jumony Core 3,真正的HTML引擎,正式版发布
Jumony是一个开源项目,已经有三年的历史了,在这三年中,秉承提供给.NET程序员完整的HTML掌控能力,Jumony历经无数次的改进,终于进入了一个新的阶段.Jumony Core 3是一个真正意 ...
- jsoup-处理html中的script数据
/** * 价值在线数据-左边分类抓取 * http://www.valueonline.cn/laws/laws?typeid=96219074211635284 * @author hwaggLe ...
- android 图像处理系列合集
为了便于大家对滤镜算法的学习,以后发布的图像处理滤镜系列帖子会在这里汇总,本人第一次写合集,写得不好的地方大家请见谅,手头上虽然有一些滤镜的算法,但是大多不是android版的,教程里的代码大多是我借 ...
- excel出现错误1327 无效的驱动器
错误描述:错误1327 无效的驱动器 错误程序:excel 2003 这是office安装源的位置被移动造 成的的,大部分时候安装时可能使用了移动硬盘或者在安装后调整了盘符就会造成这个问题.官方的 ...