标签:网页开发 作用 res 添加 eth 编程 oracle 查看 image
JSP全名Java Server Page,它建立在Servlet规范之上的动态网页开发技术,由Oracle(Sun)推出。
1、jsp的作用:
2、jsp和Servlet的分工:
3、jap的组成
案例:演示jsp中Java脚本的使用
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 <html>
3 <head>
4 <title>$Title$</title>
5 </head>
6 <body>
7 <%--定义局部变量--%>
8 <%
9 int a =10;
10 %>
11 <%
12 out.println(a);
13 %>
14 <%=a %>
15 <%--定义成员变量及方法--%>
16 <%!
17 int a=100;
18 public void fun1() {
19 System.out.println(a);
20 }
21 %>
22 <%--this表示引用的是成员变量--%>
23 <%
24 out.println(this.a++);
25 fun1();
26 %>
27 </body>
28 </html>
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 <html>
3 <head>
4 <title>Title</title>
5 </head>
6 <body>
7 <table border="1" align="center" width="60%">
8 <tr>
9 <td>姓名</td>
10 <td>年龄</td>
11 </tr>
12 <%
13 for (int i = 0; i < 10; i++) {
14 %>
15 <%--以下表格变成循环体--%>
16 <tr>
17 <td>张三</td>
18 <td>28</td>
19 </tr>
20 <%
21 }
22 %>
23 </table>
24 </body>
25 </html>
案例:演示jsp与servlet分工。
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 <html> 3 <head> 4 <title>Title</title> 5 </head> 6 <body> 7 <form action="/day11_1/AServlet" method="post"> 8 整数1:<input type="text" name="num1"/><br/> 9 整数2:<input type="text" name="num2"/><br/> 10 <input type="submit" value="提交"/> 11 </form> 12 </body> 13 </html>
1 @WebServlet(name = "AServlet",urlPatterns = "/AServlet")
2 public class AServlet extends HttpServlet {
3 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
4 String s1 = request.getParameter("num1");
5 String s2 = request.getParameter("num2");
6 int num1 = Integer.parseInt(s1);
7 int num2 = Integer.parseInt(s2);
8 int sum = num1+num2;
9 String sum1= String.valueOf(sum);
10 request.setAttribute("result",sum1);
11 request.getRequestDispatcher("/add/result.jsp").forward(request,response);
12 }
13 }
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 <html>
3 <head>
4 <title>Title</title>
5 </head>
6 <body>
7 <%
8 String result = (String)request.getAttribute("result");
9 %>
10 <%=result %>
11 </body>
12 </html>
4、jsp原理
5、jsp注释
标签:网页开发 作用 res 添加 eth 编程 oracle 查看 image
原文地址:http://www.cnblogs.com/gdwkong/p/7624319.html