更新時間:2021-10-20 12:53:33 來源:動力節點 瀏覽1885次
這里使用IDEA構建Web應用
添加新的Tomcat
勾選上正確的Tomcat
選擇Filsh
創建好目錄如下
其自動生成的Web.XML文件如下
<?xml version="1.0" encoding="UTF-8"?>"http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
同時還生成了一個jsp文件,生成的jsp文件如下
Created by IntelliJ IDEA. User: Administrator Date: 2020/7/5 Time: 22:39 To change this template use File | Settings | File Templates.--%>"text/html;charset=UTF-8" language="java" %> $Title$ $END$
配置應用首頁
<?xml version="1.0" encoding="UTF-8"?>"http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">index.jsp
啟動相關的應用
這樣就完成了最基本的tomcat的部署
jsp的注釋
jsp的基本注釋如下
Created by IntelliJ IDEA. User: Administrator Date: 2020/7/5 Time: 22:39 To change this template use File | Settings | File Templates.--%>"text/html;charset=UTF-8" language="java" %> $Title$ $END$
jsp 聲明
對jsp的聲明如下
Created by IntelliJ IDEA. User: Administrator Date: 2020/7/5 Time: 22:39 To change this template use File | Settings | File Templates.--%>"text/html;charset=UTF-8" language="java" %> $Title$ // 聲明一個整形變量 public int count; // 聲明一個方法 public String info(){ return "hello"; } %> $END$ // 把count值輸出后加1 out.println(count++); %> // 輸出info()方法后的返回值 out.println(info()); %>
訪問的頁面結果如下
jsp 輸出表達式
jsp提供了一種簡單的輸出表達式
Created by IntelliJ IDEA. User: Administrator Date: 2020/7/5 Time: 22:39 To change this template use File | Settings | File Templates.--%>"text/html;charset=UTF-8" language="java" %> $Title$ // 聲明一個整形變量 public int count; // 聲明一個方法 public String info(){ return "hello"; } %> $END$`
這里對jsp有三個編譯的指令
page 指令
page指令位于jsp頁面的頂端,一個jsp頁面可以有多個page指令,page指令的語法為
"java.sql.*" %>
include指令
include指令可以將一個外部文件嵌入到當前jsp文件中,同時解析這個頁面中的jsp語句。include命令既可以包含jsp頁面也可以包含靜態文本。編譯指令語法如下:
"要導入的jsp頁面或文本文件" %>
taglib指令
taglib指令用于引入一些特定的標簽庫,語法格式:
"tagPrefix" uri="tagLibraryURI" %>
如使用struts標簽庫:
"s" taglib="/struts-tags" %>
forward
進行頁面跳轉的指令 如果轉發的時候需要傳遞參數可以使用jsp:param指令進行設置。比如,訪問index.jsp頁面時自動轉發至login.jsp,需要把username和password傳遞過去:index.jsp:
"java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>"login.jsp">
在login.jsp中可以使用getParameter方法獲取傳入的參數值:
String name=request.getParameter("username"); String pwd=request.getParameter("password"); out.println(name); out.println(""); out.println(pwd);%>
執行forword指令時用戶請求的地址沒有發生變化,頁面內容被forward目標替代。
include指令
include指令用于包含某個頁面,但不會導入被include頁面的編譯指令。可以通過param指令傳遞參數:新建一個index.jsp
"java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>html>"head.html">"body.jsp">
body.jsp
"bgcolor")%>">
以上就是關于“IDEA創建JSP頁面”的介紹,大家可要牢記哦。
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習