当前位置: 首页 > ds >正文

struts2通配符使用

【例】使用通配符实现用户登录与注册
第一步:编写action
package com.dwx.actions;
import com.opensymphony.xwork2.ActionSupport;
public class userAction extends ActionSupport{private String username;private String password;private String age;private String sex;public String getAge() {return age;}public void setAge(String age) {this.age = age;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String login(){return SUCCESS;}public String regist(){return "regist_info";}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;}
}
第二步:配置struts2.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="user" extends="struts-default" namespace="/"><action name="user*" class="com.dwx.actions.userAction" method="{1}"><result name="success">/success.jsp</result><result name="regist_info">/regist_info.jsp</result></action></package>
</struts>
第三步:编写登录页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>">   <title>用户登录</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"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css">a{text-decoration: none;}</style></head> <body><center><s:form action="userlogin" method="post" name="loginForm"><s:textfield name="username" label="用户名"></s:textfield><s:password name="password" label="密码"></s:password><s:submit value="登录"></s:submit><s:a href="regist.jsp">注册</s:a> </s:form></center></body>
</html>
第四步:编写注册页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>注册页面</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"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><center><s:form action="userregist" method="post"><s:textfield name="username" label="用户名"></s:textfield><s:password name="password" label="密码"></s:password><s:textfield name="age" label="年龄"></s:textfield><s:radio name="sex" label="性别" list="{'男','女' }"  value="男"></s:radio><s:submit value="注册"></s:submit></s:form></center></body>
</html>
第五步:编写登录成功页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>">   <title>登录成功</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"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head>  <body><h3 align="center">登录成功</h3><hr><center>欢迎:<s:property value="username" /></center></body>
</html>
第六步:编写注册成功页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>注册信息</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"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><h3 align="center">注册信息</h3><hr><center>用户名:<s:property value="username" /><br>密码:<s:property value="password" /><br>年龄:<s:property value="age"/><br>性别:<s:property value="sex"/><br></center> 		</body>
</html>
效果:
登录页面(login.jsp)


注册页面(regist.jsp)


登录成功页面(success.jsp)


注册成功页面(regist_info.jsp)


http://www.xdnf.cn/news/11145.html

相关文章:

  • 如何在VirtualBox虚拟机中安装XP系统? 转
  • Android签名机制及PMS中校验流程(雷惊风)
  • Cadence Allegro PCB设计88问解析(七) 之 Allegro位号反标OrCAD
  • Java版文本编辑器
  • socks5 运行几个小时后 端口10808不通了,ss5服务正常
  • Spring整合Quartz框架实现定时任务跑批(Maven完整版)
  • 超级详细的GitLab安装 与使用 【Gitlab添加组、创建用户和项目、权限管理】_gitlab群组
  • 探秘GPT:开启人工智能语言模型的新纪元
  • Yandex 邮箱添加
  • 麒麟短线王至尊版 软件及指标 应用!
  • Linux系统下安装部署Linux管理面板1panel
  • Win11系统提示找不到olecli32.dll文件的解决办法
  • web.xml中context-param的配置作用
  • dll和so文件区别与构成
  • 世界环保创业基金会简介
  • LDAP 目录服务器的现代化应用
  • 动态实现RelativeLayout,LinearLayout布局
  • Lenovo笔记本新版Veriface Pro(人像识别)软件介绍
  • InstallShield 12 制作安装包
  • anaconda安装gdal、Fiona、shapely、pyproj、geopandas
  • size mismatch: error 在搭建网络的时候
  • 使用JavaScript实现选项卡
  • java内存区域理解-初步了解
  • 洛谷 P2452 [SDOI2005] 屠龙传说-屠龙枪卷
  • 2022-04-30 Unity核心2——Sprite
  • 10种用于渗透测试的漏洞扫描工具有哪些_渗透测试和漏洞扫描区别_渗透漏洞分级工具
  • Android2.2快速入门
  • 13种网页QQ代码
  • MFC自绘入门(一)
  • 华硕电脑无法安装Ubuntu 11.04(10.10同)