View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2014年4月11日 下午7:45:24
4    */
5   package gboat2.base.view.components;
6   
7   import java.io.Writer;
8   
9   import javax.servlet.http.HttpServletRequest;
10  import javax.servlet.http.HttpServletResponse;
11  
12  import org.apache.struts2.components.UIBean;
13  import org.apache.struts2.views.annotations.StrutsTag;
14  
15  import com.opensymphony.xwork2.util.ValueStack;
16  
17  /**
18   * 在JSP页面输出当前页面路径的注释
19   * @author sunpf
20   * @since 3.0
21   * @date 2014-7-1
22   */
23  @StrutsTag(
24          name="pageurl",
25          tldTagClass="gboat2.base.view.jsp.PageUrlTag",
26          description="输出当前页面路径",
27          allowDynamicAttributes = false)
28  public class PageUrl extends UIBean {
29  	
30      public static final String TEMPLATE = "pageurl";
31      
32      private String pageUrl;
33      
34      public PageUrl(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
35          super(stack, request, response);
36          String actionName= stack.getRoot().get(0).getClass().getName();
37          String packageName = "";
38          if(actionName.contains(".action")){
39          	packageName = actionName.split(".action")[0];
40          }
41          pageUrl = packageName+"/src/main/resources";
42      }
43  
44      @Override
45      protected String getDefaultTemplate() {
46          return TEMPLATE;
47      }
48  
49      @Override
50      protected void evaluateExtraParams() {
51          super.evaluateExtraParams();
52          pageUrl += (String) request.getAttribute("javax.servlet.include.servlet_path");
53          addParameter("pageUrl",pageUrl);
54      }
55  
56      @Override
57  	public boolean end(Writer writer, String body) {
58  		return super.end(writer, body);
59  	}
60  }