時(shí)間:2023-05-24 05:21:01 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-05-24 05:21:01 來(lái)源:網(wǎng)站運(yùn)營(yíng)
Java Web開發(fā)流程的步驟?。阂?jiǎng)?chuàng)建 Web 應(yīng)用程序,告訴大家需要以下Java開發(fā)工具:導(dǎo)入 java.io.IOException; 導(dǎo)入 javax.servlet.ServletException; 導(dǎo)入 javax.servlet.annotation.WebServlet; 導(dǎo)入 javax.servlet.http.HttpServlet; 導(dǎo)入 javax.servlet.http.HttpServletRequest; 導(dǎo)入 javax.servlet.http.HttpServletResponse; /** * Servlet 實(shí)現(xiàn)類 TestServlet */ @WebServlet ( "/TestServlet" ) 公共類 TestServlet 擴(kuò)展 HttpServlet { 私有靜態(tài)最終長(zhǎng) 序列版本UID = 1L; /** * @see HttpServlet#HttpServlet() */ 公共 TestServlet(){ 超級(jí)(); // TODO 自動(dòng)生成的構(gòu)造函數(shù)存根 } /** * @see HttpServlet#doGet(HttpServletRequest 請(qǐng)求,HttpServletResponse 響應(yīng)) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO 自動(dòng)生成的方法存根 response.getWriter().append( "服務(wù)于:" ).append (request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest 請(qǐng)求,HttpServletResponse 響應(yīng)) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO 自動(dòng)生成的方法存根 doGet(請(qǐng)求,響應(yīng)); } }
<!DOCTYPE html > < html > <頭> <元字符集= < em > “UTF-8” < / em > < title >第一個(gè)Web應(yīng)用程序</ title > </頭> <身體> < h1 >歡迎</ h1 > < ul > < li > <a href="#">首頁(yè)</a> < / li > _ _ _ _ _ < li > <a href="#">新聞</a> < / li > _ _ _ _ _ < li > <a href="#">聯(lián)系方式</a> < / li > _ _ _ _ < li > <a href="#">關(guān)于</a> < / li > _ _ _ _ _ </ ul > </正文> </ html >
<小服務(wù)程序> < servlet 名稱> MyHttpTestServlet </ servlet 名稱> < servlet-class > TestServlet </ servlet-class > </小服務(wù)程序> < servlet 映射> < servlet 名稱> MyHttpTestServlet </ servlet 名稱> < url-pattern > /歡迎</ url-pattern > </ servlet-mapping >
我們還可以定義我們的歡迎文件;歡迎文件是啟動(dòng)項(xiàng)目的項(xiàng)目的第一個(gè)文件,也稱為 Home。我們可以定義多個(gè)歡迎文件。<? xml版本= "1.0"編碼= "UTF-8" ?> <網(wǎng)絡(luò)應(yīng)用xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation = "http ://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id = "WebApp_ID"版本= "3.1" > <顯示名稱> BasicWebApplication </顯示名稱> <歡迎文件列表> <歡迎文件> index.html </歡迎文件> <歡迎文件> index.htm </歡迎文件> <歡迎文件> index.jsp </歡迎文件> <歡迎文件> default.html </歡迎文件> <歡迎文件> default.htm </歡迎文件> <歡迎文件> default.jsp </歡迎文件> </歡迎文件列表> <小服務(wù)程序> < servlet 名稱> MyHttpTestServlet </ servlet 名稱> < servlet-class > TestServlet </ servlet-class > </小服務(wù)程序> < servlet 映射> < servlet 名稱> MyHttpTestServlet </ servlet 名稱> < url-pattern > /歡迎</ url-pattern > </ servlet-mapping > </網(wǎng)絡(luò)應(yīng)用>
從上面的代碼中,我們可以看到servlet默認(rèn)定義了幾個(gè)歡迎文件。如果要使用列出的文件以外的任何文件,可以在此處定義。<!DOCTYPE html > < html > <頭> <元字符集= “UTF-8” > < title >第一個(gè)Web應(yīng)用程序</ title > </頭> <風(fēng)格> ul { 列表樣式類型:無(wú); 邊距:0; 填充:0; } 身體 { 背景顏色:#E6E6FA; } </風(fēng)格> <身體> < h1 >歡迎</ h1 > < ul類= “點(diǎn)” > < li > <a href="#">首頁(yè)</a> < / li > _ _ _ _ _ < li > <a href="#">新聞</a> < / li > _ _ _ _ _ < li > <a href="#">聯(lián)系方式</a> < / li > _ _ _ _ < li > <a href="#">關(guān)于</a> < / li > _ _ _ _ _ </ ul > < img alt = "圖像" src = "image.jpg"寬度= "300"高度= "200" > </正文> </ html >
將圖像文件添加到WebContent文件夾中。關(guān)鍵詞:步驟,流程
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。