struts2登录验证小程序

网友投稿 502 2022-10-07

struts2登录验证小程序

struts2登录验证小程序

1.必备的struts2-blank.war下的lib目录下的所有驱动包,放入项目下的lib目录中。

2.新建一个UserAction类,代码如下:

package com.eduask; import com.opensymphony.xwork2.ActionSupport; //创建一个UserAction继承ActionSupport类; public class UserAction extends ActionSupport{ private String userName; private String userPassWord; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserPassWord() { return userPassWord; } public void setUserPassWord(String userPassWord) { this.userPassWord = userPassWord; } @Override public String execute() throws Exception { if("tom".equals(userName)&&"123456".equals(userPassWord)) return "success"; else return "error"; } }

3.在src目录下新建一个struts.xml的配置文件,代码如下:

/success.jsp /error.jsp

4.在webRoot目录下新建三个jsp文件,分别是success.jsp、error.jsp、index.jsp

5.success.jsp代码如下:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <% String path=request.getContextPath(); String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort(); %> my success jsp page

欢迎<%=request.getParameter("userName") %>登录

6.error.jsp代码如下: <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <% String path=request.getContextPath(); String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> my error jsp page

用户名或密码错误

7.index.jsp代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> My JSP 'index.jsp' starting page

用户名
密码

8.最后修改web.xml的配置文件,修改结果为:

标签:js
上一篇:Zabbix5.0监控指定文件目录下的文件数量
下一篇:console怎样打印日志信息(如何查看打印日志)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~