zoukankan      html  css  js  c++  java
  • jsp入门

    无需配置:

    第一个jsp程序:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    //在这里实现java片段
    out.print("Hello,world!"+"当前日期="+new java.util.Date());
    %>>
    </body>
    </html>
    View Code

     

    jsp提供9个j内置对象

     1.脚本元素

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%int i=100; %>
    <h1>显示</h1>
    <%out.print("i="+i); %>>
    <%=i*4+4 %>>
    </body>
    </html>
    View Code

    2.变量与函数

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    
    <%!
    public int test(int a,int b){
        return (a+b);
    }
    %>
    <%! int i=90; %>
    <% int j=100;
    out.print("i="+(++i)+"  j="+(++j)+"a+b="+test(i,j));
    %>
    </body>
    </html>
    View Code

     

    转发;

    jsp:forward

    Manager.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    管理页面
    </body>
    </html>
    View Code

    Enter,jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <jsp:forward page="/Manager.jsp"></jsp:forward>>
    
    </body>
    </html>
    View Code

    当把文件放入到WEB_INF中,forward则发挥作用(防止用户直接访问)

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <jsp:forward page="/WEB-INF/jsp1.jsp"></jsp:forward>
    </body>
    </html>
    View Code

     jsp:include

    Enter.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <jsp:include page="/Manager.jsp"></jsp:include>
    
    </body>
    </html>
    View Code

    Manager,jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    管理页面
    </body>
    </html>
    View Code

  • 相关阅读:
    QTextStream 居然接受FILE*这样的传统参数
    基于IOCP的高速文件传输代码
    tornado web框架
    Kaggle入门
    NET Core 介绍
    Wireshark
    设计和应用分布式调用跟踪系统
    Visual Studio Code和Docker开发asp.net core和mysql应用
    背单词
    多环境开发
  • 原文地址:https://www.cnblogs.com/helloworld2019/p/11023013.html
Copyright © 2011-2022 走看看