menu
more_vert
jsp元素

作者:dayu

技术分享
 1 <!-- 指令元素page -->
 2 <%@ page language="java" contentType="text/html; charset=UTF-8"
 3     pageEncoding="UTF-8" import="java.util.Date"%>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8 <title>Insert title here</title>
 9 </head>
10 <style>
11 body {
12     margin: 0px
13 }
14 
15 </style>
16 <body>
17 <%
18  Date a=new Date();
19 System.out.print(a);
20 %>
21 <!-- 指令元素include -->
22 <%@ include file="include.jsp" %>
23 </body>
24 </html>

View Code
技术分享技术分享
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 
 4 <table border="1">
 5 <tr>
 6 <td>1</td>
 7 <td>2</td>
 8 <td>3</td>
 9 </tr>
10 <tr>
11 <td>4</td>
12 <td>5</td>
13 <td>6</td>
14 </tr>
15 <tr>
16 <td>7</td>
17 <td>8</td>
18 <td>9</td>
19 </tr>
20 </table>

View Code

2.脚本元素:编写可在服务器端执行的Java代码块
a .声明元素 :不产生输出,声明成员变量和方法

b.脚本段:产生输出

c.表达式:是Java语言中标准的表达式,请求处理计算表达式的值。

方法只能写在声明元素中,变量可以写在声明元素和脚本段中

技术分享技术分享
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <!--  脚本元素之声明元素-->
11 <%!
12 String str="123";
13 public int add(int a,int b)
14 {
15     return (a+b);
16 }
17 
18 %>
19 <!-- 脚本元素之脚本段 -->
20 <% 
21   out.print(add(2,3));
22   
23   
24 %>
25 <!--  脚本元素之表达式 -->
26 <input type="text" value="<%=str%>"/>
27 
28 </body>
29 </html>

View Code

动作元素:

<jsp:forward>

技术分享技术分享
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9   <%
10      String result = request.getParameter("userN");
11      out.print("<h2>欢迎用户:"+result+"登录成功!</h2>");
12   %>
13 
14 <body>
15 
16 </body>
17 </html>

View Code
技术分享技术分享
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9  <%
10    //获取用户名:
11    String userName = request.getParameter("userName");
12     //密码:
13     String password = request.getParameter("password");
14  
15  %>
16 
17  
18 
19 <body>
20  
21   <script type="text/javascript">
22     var userName = "<%=userName%>";
23     var password = "<%=password%>";
24     alert(userName)
25 /*    if("admin"== userName && "123" == password)
26    {
27       location.href="welcome.jsp?userN="+userName+"&pass="+password;  
28    }
29    else
30    {
31        
32    } */
33  
34  </script>
35  
36  <%
37    if("admin".equals(userName) && "123".equals(password))
38    {
39    %>
40        <jsp:forward page="welcome.jsp">
41            <jsp:param value="<%=userName%>" name="userN"/>
42        </jsp:forward>
43   <% }
44   else{
45   %>
46       <jsp:forward page="login01.jsp"/>
47  <%  }
48   %>
49 
50   
51 
52 </body>
53 </html>

View Code

jsp元素

原文地址:http://www.cnblogs.com/zclqian/p/7218546.html