java代码段+jsp的基础应用

阅读更多

项目需要大量使用自定义标签,讨厌的<%%>和<%=-%>,加上html+js+jquery

那么好吧,玩吧! 记下来,给自己个备忘。

 

1.先上个基础的,复习一下

  注意:定义的变量,可以直接在js中使用,当做参数或值。这很重要,即传来的参数就可以在这直接用到js中

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

<%
	String name = "mengxianjun";
	String inputReadonly = "readonly='true'";
%>


  
    
    
    My JSP 'index.jsp' starting page
	
	
	    
	
	
	
  
  
  
    />
  


    

2.自定义标签,怎么使用(PSAreaTag.tag)

<%@ tag pageEncoding="UTF-8" import="java.util.*,com.hanpeng.base.util.SelectManagerRequest" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="id"  required="true" rtexprvalue="true"%>
<%@ attribute name="name"  required="true" rtexprvalue="true"%>

<%@ attribute name="pid"  required="false" rtexprvalue="true"%>
<%@ attribute name="action" required="false" rtexprvalue="true"%>

<%@ attribute name="isSelect"   required="false" rtexprvalue="true" %> 
<%@ attribute name="isShowHead"   required="false" rtexprvalue="true" type="java.lang.Boolean"%> 
<%@ attribute name="headinfo"   required="false" rtexprvalue="true" %> 
<%@ attribute name="sendMethod"   required="false" rtexprvalue="true" %> 
<%@ attribute name="disabledstate"   required="false" rtexprvalue="true" %> 
<%@ attribute name="widlength"   required="false" rtexprvalue="true" %> 
<%@ attribute name="diyClass"   required="false" rtexprvalue="true" %> 
<%
	List list = null;
	if(pid == null && sendMethod != null){
		if("areaLinkMenus".equals(sendMethod)) list = SelectManagerRequest.getAreaProvince(request);/* 省市联动 */
		if("inOrOutProvince".equals(sendMethod)) list = SelectManagerRequest.getInOrOutProvince(request);/* 省市联动 */
	}
%>


<%if(pid != null && !pid.equals("") && action != null && !action.equals("")){ %>


<%} %>

 

 

你可能感兴趣的:(java代码段,自定义标签)