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




	
		
			/success.jsp
			/regist_info.jsp
		
	

第三步:编写登录页面

<%@ 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+"/";
%>


  
       
    用户登录    
	
	
	    
	
	
	
  
   
  
    
注册

第四步:编写注册页面

<%@ 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+"/";
%>



  
    
    
    注册页面
    
	
	
	    
	
	
	

  
  
  
    

第五步:编写登录成功页面

<%@ 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+"/";
%>


  
       
    登录成功    
	
	
	    
	
	
	
    
  
  

登录成功


欢迎:

第六步:编写注册成功页面

<%@ 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+"/";
%>



  
    
    
    注册信息
    
	
	
	    
	
	
	
  
  
  
  

注册信息


用户名:
密码:
年龄:
性别:

效果:

登录页面(login.jsp)

struts2通配符使用_第1张图片

注册页面(regist.jsp)

struts2通配符使用_第2张图片

登录成功页面(success.jsp)


注册成功页面(regist_info.jsp)

struts2通配符使用_第3张图片

你可能感兴趣的:(struts2)