C:\Users\Administrator\.IntelliJIdea2018.3\system\tomcat\Unnamed_JavaWebStudy\work\Catalina\localhost\ROOT\org\apache\jsp

 

Jsp本质就是一个Servlet 

 

 

 

 JSP的基本语法

 

 

 

 

 

 

 

 

 

 

 

 

 重要!! 

 

 

 

JSTL标签示例:

<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/5/14 0014
  Time: 19:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
<h1>主页面</h1>
<form action="index.jsp" method="get">
<input type="text" name="username" value="${param.username}">
  <input type="submit" value="登录">
</form>

<c:if test="${param.username=='admin'}" var="isAdmin">
  <c:out value="管理员欢迎你"></c:out>
</c:if>
<c:out value= "${isAdmin}"></c:out>


  <%
    String a="六六大顺";
    String bb="六六大顺bb";
    ArrayList<String> people = new ArrayList<>();
    people.add("张三");
    people.add("李四");
    people.add("张五");
    people.add("张六");
    people.add("张七");
    people.add("张八");
    //这样才能取到数据
    request.setAttribute("list",people);
  %>
<%--输出格式--%>
<%=a%>
<%--EL表达式只能从四大域中获取属性,java中自己定义的获取不到--%>
${bb}
<h3>name=${bb}</h3>
<c:forEach var="peo" items="${list} ">
  <c:out value="${peo}"></c:out><br>
</c:forEach>


  </body>
</html>

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐