一、说明几点: (2)类型 // <% string url = "javascript:back('" + s + "')"; %> 4. javascript --> java
(1)过程描述:
jsp文件首先在服务器端生成中间的java文件,再生成class,然后以html的形式返回到客户端。
所以说,一个jsp文件首先执行其中的java代码,然后生成html。
a.java类型(就不描述了)
b.javascript 的类型
string, number, boolean,undefined and null,
object, array, date, math 等
javascript 是一种dynamic typing,every javascript variable has a data type,
but the type is inferred from the variable’s content.
//var favnumber;
//favnumber = 3;
//favnumber = "san diego";
//first, when the variable favnumber is declared, it is empty. in fact,
//its data type is actually the type undefined. then we assign it to the number 3,
//so its data type is 3. next we reassign it to the string "san diego",
//so the variable’s type is now string. as you can see, types are inferred from content,
//and a variable automatically takes on the type of the data it contains.
二、交互
1 java --> html
直接使用表达式 <%= variable %>
// <link rel="stylesheet" href="<%= urlpath %>/cws/css/cws.css" type="text/css">
2 java --> javascript
由于两种类型的不同,如果java的值能够转化成数字。
string i ="1.02";
integer i = new integer(22);
float i = 10;
都可以直接和javascript的类型交互,即直接传给javascript变量
// <input type="button" name="back" value="back" onclick ="back(<%= i %>)" >
// 也可以<input type="button" name="back" value="back" onclick ="back('<%= i %>')" >
如果java的值不能够转化成数字
string s ="1.jsp";
需要转化为javascript的字符串类型
// <input type="button" name="back" value="back" onclick ="back('<%= s %>')" >
// <input type="button" name="back" value="back" onclick ="<%=url%>" >
3. html --> java
<%java code...
%>
html code....
<%java code...
%>
// <% string url = "javascript:back('" + s + "')"; %>
// <input type="button" name="back" value="back" onclick ="<%=url%>" >
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器