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'";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <input type="text" id="test" value="" οnblur="checkInput<%=name%>()" <%=inputReadonly%>/>
  </body>

<script type="text/javascript">
<%
	if(name!=null){
%>
       alert('name不为空:'+'<%=name%>');
<%
	}
%>
	var myName = '<%=name%>';
	document.getElementById('test').value=myName;
	
	function checkInput<%=name%>()
	{
		alert('input 鼠标离开事件');
	}
</script>
</html>

    

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" %> <!-- 可传任意值  如:disabled=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);/* 省市联动 */
	}
%>

<select id="<%=id %>" name="<%=name %>"  class="<%=diyClass %>" 
		<%=disabledstate %> 
		style="<%=widlength %>">
	<%     if(isShowHead != null && isShowHead == true){   %>
	<%         if(headinfo != null){ %>
					<option value="" selected ><%=headinfo %></option>
	<%         }else{                %>
					<option value="" selected >请选择</option>
	<%         } 					 %>
	<%     }                         %>
	<% if(list != null && !list.isEmpty()){             %>
	<%     for (int i=0;i<list.size();i++ ){
		      java.util.HashMap ot = (java.util.HashMap)list.get(i);
		      String oti = ot.get("val").toString();
		      String selected = "";
		      if(oti.equals(isSelect)){
			      selected = "selected";
		      }
	%>
		      <option value="<%=ot.get("val")%>" name="<%=ot.get("key") %>" &nbsp; <%=selected%> ><%=ot.get("key")%></option>
	<%     }   %>
	<% }       %>
</select>
<%if(pid != null && !pid.equals("") && action != null && !action.equals("")){ %>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/doubleCombo/doubleCombo.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  new DoubleCombo("<%=pid %>","<%=id %>","<%=action %>",{
	errorHandler:function(request){
		alert("网络交互出错");
	}
	<%     if(isShowHead != null && isShowHead == true){   %>
	<%         if(headinfo != null){ %>
					,head: '<%=headinfo %>'
	<%         }else{                %>
					,head: '请选择'
	<%         } 					 %>
	<%     }                         %>
	<%     if(isSelect != null){     %>
					,defaultChild: '<%=isSelect %>'
	<%     }                         %>
	}).masterComboChanged();
});
</script>
<%} %>

 

 

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值