JAVA_WEB Struts2学习:Struts2Ajax标签的学习

导入Struts2 Ajax标签:

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/struts-dojo-tags" prefix="sx" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
  	


Struts2 Ajax标签 实例1:

index:


<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/struts-dojo-tags" prefix="sx" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
  	
    
    
    DOJO学习
	
	
	    
	
	
	
  
  
   
    
    	
    	
    
    	
    	
    	
    		这是初始化DIV层 
    	
    
  



struts2.xml:






		
			/jsp/time.jsp
			/jsp/welcome.jsp
			/MyJsp.jsp
		
	

    



public class MyTestAction extends ActionSupport

package com.zuxia.yc42.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class MyTestAction extends ActionSupport 
{
	private Long time;
	private String usName;
	private String usPass;
	
	private String msg;
	
	public String times()
	{
		long currentTime = System.currentTimeMillis(); //获取当前时间
		
		HttpSession session =ServletActionContext.getRequest().getSession();
		
		//获取开始时间
		Long startTime = (Long) session.getAttribute("startTime");
		
		if (startTime == null) 
		{ 
			//第一次访问
			startTime = currentTime;
			session.setAttribute("startTime", startTime);
		}
		
		time =(currentTime-startTime)/1000;//以秒计算的已用时间

		return "time";
	}
	
	public String login()
	{
		if(usName.equals("admin") &&usPass.equals("123"))
		{
			msg = "登陆成功";
		}else
		{
			msg = "登陆失败";
		}
		
		return "login";
	}
	
	public String welcome()
	{
		return "welcome";
	}

	public Long getTime() {
		return time;
	}

	public void setTime(Long time) {
		this.time = time;
	}

	public String getUsName() {
		return usName;
	}

	public void setUsName(String usName) {
		this.usName = usName;
	}

	public String getUsPass() {
		return usPass;
	}

	public void setUsPass(String usPass) {
		this.usPass = usPass;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}


	
}



time.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    
    
    My JSP 'time.jsp' starting page
    
	
	
	    
	
	
	

  
  
  
    您已经访问本网站



welcome.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    
    
    My JSP 'welcome.jsp' starting page
    
	
	
	    
	
	
	

  
  
  
    欢迎您访问本网站




Struts2 Ajax标签 实例2:

show.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/struts-dojo-tags" prefix="sx" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
  	
    
    
    My JSP 'show.jsp' starting page
    
	
	
	    
	
	
	

  
  
  
    登陆
    
    	图层二
    
    
    	图层三
    
  




login.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/struts-dojo-tags" prefix="sx" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
  	
    
    
    My JSP 'login.jsp' starting page
    
	
	
	    
	
	
	

  
  
  
   	
   		



struts.xml:






		
			/jsp/time.jsp
			/jsp/welcome.jsp
			/MyJsp.jsp
		
	

    



public class MyTestAction extends ActionSupport :

package com.zuxia.yc42.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class MyTestAction extends ActionSupport 
{
	private Long time;
	private String usName;
	private String usPass;
	
	private String msg;
	
	public String times()
	{
		long currentTime = System.currentTimeMillis(); //获取当前时间
		
		HttpSession session =ServletActionContext.getRequest().getSession();
		
		//获取开始时间
		Long startTime = (Long) session.getAttribute("startTime");
		
		if (startTime == null) 
		{ 
			//第一次访问
			startTime = currentTime;
			session.setAttribute("startTime", startTime);
		}
		
		time =(currentTime-startTime)/1000;//以秒计算的已用时间

		return "time";
	}
	
	public String login()
	{
		if(usName.equals("admin") &&usPass.equals("123"))
		{
			msg = "登陆成功";
		}else
		{
			msg = "登陆失败";
		}
		
		return "login";
	}
	
	public String welcome()
	{
		return "welcome";
	}

	public Long getTime() {
		return time;
	}

	public void setTime(Long time) {
		this.time = time;
	}

	public String getUsName() {
		return usName;
	}

	public void setUsName(String usName) {
		this.usName = usName;
	}

	public String getUsPass() {
		return usPass;
	}

	public void setUsPass(String usPass) {
		this.usPass = usPass;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}


	
}



MyJsp.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    
    
    My JSP 'MyJsp.jsp' starting page
    
	
	
	    
	
	
	

  
  
  
    
  





你可能感兴趣的:(Struts2)