学习 Jsp 的一点记录

来源:互联网 发布:小学多媒体教学软件 编辑:程序博客网 时间:2024/04/30 00:29

servlet 是 “Java 代码嵌套 Html”, 而 JSP is “HTML代码嵌套 Java”.

JSP 转化为 Servlet

Html 代码会用 Servlet 的 out.write()输出,而 Java 代码会保持原样

<p>The square root of 5 is <%= Math.sqrt(5) %></p><h5><%= item[10] %></h5><p>Current time is: <%=  new java.util.Date() %></p>

上面的代码会被转化为如下格式

out.write("<p>The square root of 5 is ");out.print( Math.sqrt(5) );out.write("</p>");out.write("<h5>");out.print( item[10] );out.write("</h5>");out.write("<p>Current  time is: ");out.print( new java.util.Date()  );out.write("</p>");

而 Java 代码

<%  String author = request.getParameter("author");  if (author != null && !author.equals(""))) { %>    <p>You have choose author <%= author %></p><%  }%>

会保持原样

String author = request.getParameter("author");if (author != null && !author.equals(""))) {  out.write("<p>You have choose author ");  out.print( author );  out.write("</p>");}

参考文章

Java Server-side Programming Getting started with JSP by Examples

0 0
原创粉丝点击