javaWeb之jsp(一)输出hello world


out.println()的使用

此处定义的str为jsp局部变量

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title heretitle>
head>
<body>
    <%
        String str = "hello world";
        out.println(str);
    %>
body>
html>

其中< body >体内使用<% %>包裹的为jsp代码

jap声明的使用

声明的变量为全局变量

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title heretitle>
head>
<body>
    <%!
        String str = "hello world"; 
    %>
    <%
        out.println(str);
    %>
body>
html>

jsp表达式

jsp表达式是符合java语法的表达式,它可以将java表达式的值作为字符串直接输出

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title heretitle>
head>
<body>
    jsp表达式<%="hello word" %>
    <%!
        String str = "hello world"; 
    %>
    <%
        //String str = "hello world";
        out.println(str);
    %>
body>
html>

你可能感兴趣的:(javaWeb)