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的配置文件,代码如下:
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(); %> ">