Struts2 Landing blocker (FIX)

Source: Internet
Author: User

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><!--override Struts2 Some constants default value--<constant name=" Struts.enable.DynamicMethodInvocation "value=" true "/> <constant name=" Struts.devmode "value=" true "/> < Constant Name= "struts.action.extension" value= "Action,,do" ></constant> <constant name= " Struts.configuration.xml.reload "value=" true "></constant> <constant name=" Struts.locale "value=" ZH_CN " ></constant> <package name= "mydefaultpackage" extends= "Struts-default" > <interceptors><!-- Just define the Interceptor--><interceptor name= "Timecost" class= "Com.itheima.interceptor.TimeCostInterceptor" ></ Interceptor><interceptor name= "Logincheck" class= "Com.itheima.interceptor.LoginCheckInterceptor" >< param name= "excludemethods" >sayHello1</param><!--excluded from blocking--></interceptor><!--Definition group--><interceptor-stack name= "Mydefaultstack" >< Interceptor-ref name= "Annotationworkflow" ></interceptor-ref><!--<interceptor-ref name= "Logincheck "></interceptor-ref>--><interceptor-ref name=" Timecost "></interceptor-ref>< Interceptor-ref name= "Defaultstack" ></interceptor-ref></interceptor-stack></interceptors> <default-interceptor-ref name= "Mydefaultstack" ></default-interceptor-ref> </package>< Package Name= "P1" extends= "mydefaultpackage" ><action name= "test1" class= "Com.itheima.actions.ActionDemo1" ><result>/index.jsp</result><result name= "Logincheckfailure" >/failure.jsp</result> </action><action name= "test2" class= "Com.itheima.actions.ActionDemo2" ><result>/index.jsp</ Result></action></package></struts>

Timecostinterceptor

Package Com.itheima.interceptor;import Com.opensymphony.xwork2.actioninvocation;import com.opensymphony.xwork2.interceptor.abstractinterceptor;//statistics action Method Execution Efficiency Interceptor public class Timecostinterceptor extends Abstractinterceptor {//Core intercept method public String intercept (actioninvocation invocation) throws Exception {Long startTime = System.nanotime ();//nanosecond: 1s=1000000000 nanosecond string result = Invocation.invoke ();//Let the next execution long endTime = System.nanotime (); System.out.println (Invocation.getinvocationcontext (). GetName () + "cost Time:" + (Endtime-starttime) + "ns"); return Result;}}

Logincheckinterceptor

Package Com.itheima.interceptor;import Org.apache.struts2.servletactioncontext;import Com.opensymphony.xwork2.actioninvocation;import Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor; public class Logincheckinterceptor extends Methodfilterinterceptor {protected String dointercept (actioninvocation Invocation) throws Exception {String user = (string) servletactioncontext.getrequest (). GetSession (). getattribute (" User "); String result = "Logincheckfailure"; if (user!=null) {result = Invocation.invoke ();} return result;}}

failure.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

login.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

  

Struts2 Landing blocker (FIX)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.