使用Struts2实现简单用户登录
来源:互联网 发布:模拟炒股哪个软件好 编辑:程序博客网 时间:2024/05/21 11:21
使用Struts2实现简单用户登录
类库的选择
struts2下载地址
解开压缩包后,可根据此路径得到我们需要的类库所在地。
struts-2.3.28-all\struts-2.3.28\apps\struts2-blank\WEB-INF\lib
根据此图挑选struts2的核心类库。
环境搭建
首先打开idea,点击create new project 创建一新的项目。
选择java sdk版本以及所需要的框架。在最下面一行library中你可以选择自定义类库也可以让idea自动下载struts2类库(简单方便,不易出错)。
自定义类库,点击create后出现如下图新选框。找到刚才解压好的类库,选中全部jar包后,点击ok。idea会自动为其命名。
完成后一路next…
刚出现为项目命名时,点击finish完成。
当项目中出现struts.xml文件和web.xml文件时就说明环境已基本搭建成功。
登录功能的实现
项目目录
首先先写Action
package com.csdn.hoictas.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport { private String name; private String password; public LoginAction() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String execute() { if ("hoictas@qq.com".equals(name) && "123".equals(password)) { return SUCCESS; } return ERROR; } }
然后,在struts.xml文件中注册action
<?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="demo" extends="struts-default" namespace="/"> <action name="login" class="com.csdn.hoictas.action.LoginAction" method="execute"> <result name="success" type="dispatcher">/success.html</result> <result name="error" type="dispatcher">/error.html</result> </action> </package></struts>
界面
前台用的是jsp+bootstrop,实现的简单Login界面。注意红圈内的几处地方初学者容易出错。
一切都准备就绪后,启动tomcat,访问http://localhost:你的端口号/
<welcome-file-list> <welcome-file>index.jsp</welcome-file></welcome-file-list>
如果你在web.xml文件中,加了以上代码。tomcat会根据上面的地址自动访问index.jsp。
先输入正确的邮箱地址和密码。
成功。
再输入错误的。
Ok!
源码地址
2016/12/15 2:32:52
0 0
- 使用Struts2实现简单用户登录
- struts2 简单实现用户登录
- 使用jdbc实现简单的用户登录
- struts2实现登录用户的简单的权限设置
- struts2 简单注解配置实现用户登录
- jsp实现简单用户登录
- JSP实现简单用户登录
- java之Struts2实现用户登录过滤
- struts2+ajax+json实现用户登录
- struts2连接数据库实现用户登录
- Struts2 mybatis spring 实现用户登录
- 防止未登录用户操作—struts2拦截器简单实现
- 防止未登录用户操作—struts2拦截器简单实现
- 防止未登录用户操作—struts2拦截器简单实现
- 防止未登录用户操作—struts2拦截器简单实现
- 防止未登录用户操作—struts2拦截器简单实现
- 防止未登录用户操作—struts2拦截器简单实现
- 防止未登录用户操作—struts2拦截器简单实现
- mongodb数据库启动和停止
- 关于cordova混合型app使用input file注意事项
- ubuntu下eclipse + NS3环境搭建
- AssetBundle for unity
- greenDao使用时遇到的坑
- 使用Struts2实现简单用户登录
- OJ.最简单的计算机
- maya scriptjob
- 一个简单的UDP接收例子
- ORALE SQLPLUS 检索结果不在一行
- SpringMVC基于注解进行URL映射
- Leetcode在线编程roman-to-integer
- 技术这个东西
- 分享計算機圖形學基礎教學