JSP(JavaSever Page)基础

特点:

  1. 内容的生成和显示分离
  2. 平台无关性

主流web技术:CGI、ASP、PHP、JSP

 

tomcat配置: 

.jsp文件中的代码:<%除界面外的Java代码%>

注:out.println();输出到网页页面,System.out.println();输出到tomcat终端界面

jsp运行过程:运行着tomcat,由浏览器指定文件运行由浏览器向tomcat申请文件,tomcat运行文件的结果生成html的内容,返回给浏览器)


注:需要把要运行的.jsp文件放到tomcat文件(或所在文件夹)的webapp文件下,浏览器通过localhost:8080/**/.jsp。

aaa.jsp:
<% 
   for(int i=0;i<200;i++)
   {
      out.println(i+" ");
   }
%>
--------------------------------------------------------------
bbb.jsp:
<html>
  <head>
    <title>Table Ex</title>
  </head>
  <body>
    <table border="1">
     <% 
        for(int i=0;i<8;i++)
        {
     %>
       <tr>
        <% 
          for(int j=0;j<10;j++)
          {
             out.println("<td>"+i+":"+j+"</td>");
          }         
        %>
       </tr>
     <%
        }
     %>
    </table>
  </body>
</html>
---------------------------------------------------------------
ccc.jsp
<html>
  <head>
    <title>Table Ex</title>
  </head>
  <body>
    <form action="ccc.jsp">
       Name<input type="text" name="uid"><br/>
       <input type="submit" value="OK">
    </form>
    <% 
      String uid=request.getParameter("uid");
      if(uid!=null&&uid.length()!=0)
      {
    %>
       <font color="red" size="20">
       Hello,
    <% 
        out.print(uid);
    %>
       !
       </font>
    <%
      } 
      else
      {
    %>
       <font color="red" size="20">
         Please input your name!
       </font>
    <%     
      }   
    %>
  </body>
</html>
------------------------------------------
inaaa.jsp:
<html>
  <head>
    <title>Table Ex</title>
  </head>
  <body>
    <table border="1">
     <% 
        for(int i=0;i<8;i++)
        {
     %>
       <tr>
        <% 
          for(int j=0;j<10;j++)
          {
             out.println("<td>"+i+":"+j+"</td>");
          }         
        %>
       </tr>
     <%
        }
     %>
    </table>
    <hr/>
    <%@ include file="aaa.jsp" %>
  </body>
</html>
------------------------------------------------

JSP指令

JSP脚本标签

inccc.jsp
<html>
  <head>
    <title>Table Ex</title>
  </head>
  <body>
    <table border="1">
     <% 
        for(int i=0;i<8;i++)
        {
     %>
       <tr>
        <% 
          for(int j=0;j<10;j++)
          {
             out.println("<td>"+i+":"+j+"</td>");
          }         
        %>
       </tr>
     <%
        }
     %>
    </table>
    <hr/>
    <jsp:include page="ccc.jsp">
      <jsp:param name="uid" value="wyf"/>
    </jsp:include>
  </body>
</html>

gotoccc.jsp:

aaaaaaaaa

<jsp:forward page="ccc.jsp">
  <jsp:param name="uid" value="wyf"/>
</jsp:forward>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值