B033-Servlet交互 JSP

目錄

      • Servlet
        • Servlet的三大職責
        • 跳轉:請求轉發和重定向
        • 請求轉發
        • 重定向
        • 匯總
        • 請求轉發與重定向的區別
        • 用請求轉發和重定向完善登錄
      • JSP
        • 第一個JSP
          • 概述
          • 注釋
          • 設置創建JSP文件默認字符編碼集
        • JSP的java代碼書寫
        • JSP的原理
        • 三大指令
        • 九大內置對象
          • 改造動態web工程進行示例
          • 內置對象名稱來源?
          • 名單列表
        • 四大作用域
          • 概述
          • 案例測試
          • 登錄完善

Servlet

Servlet的三大職責

1.接受參數 --> req.getParameter (非必須)
2.處理業務 --> 拿到數據后去做一些事情(非必須)
3.跳轉(必須)–> 操作完的一個結果 兩句代碼

跳轉:請求轉發和重定向

在這里插入圖片描述

請求轉發

案例演示:動態web項目

AServlet

@WebServlet("/go/a")
public class AServlet extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("AServlet");String name = req.getParameter("name");System.out.println("A-name: "+name);req.setAttribute("password", "123456");// 請求轉發req.getRequestDispatcher("/go/b").forward(req, resp);}
}

BServlet

@WebServlet("/go/b")
public class BServlet extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("BServlet");String name = req.getParameter("name");System.out.println("B-name: "+name);String password = (String) req.getAttribute("password");System.out.println("B-password: "+password);}
}

瀏覽器訪問:http://localhost/go/a?name=zhangsan

控制臺:

AServlet
A-name: zhangsan
BServlet
B-name: zhangsan
B-password: 123456

req.getRequestDispatcher(“路徑”).forward(request, response); ,請求里的東西,forward可以理解為攜帶

帶值跳轉,可以訪問WEB-INF中資源,地址欄不改變
發送一次請求,最后一個response起作用,不可以跨域[跨網站]訪問

重定向

案例演示:動態web項目

CServlet

@WebServlet("/go/c")
public class CServlet extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("CServlet");String name = req.getParameter("name");System.out.println("C-name: "+name);resp.sendRedirect("/go/d");}
}

DServlet

@WebServlet("/go/d")
public class DServlet extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("DServlet");String name = req.getParameter("name");System.out.println("D-name: "+name);}
}

瀏覽器訪問:http://localhost/go/c?name=zhangsan

控制臺:

CServlet
C-name: zhangsan
DServlet
D-name: null

resp.sendRedirect(“路徑”) ,響應里的東西,可以有避免重復扣款和訪問外部網站之類的作用

無法帶值,不能訪問WEB-INF下內容,地址欄改變
兩次請求,起作用的依然是最后一個,可以跨域訪問

匯總

在這里插入圖片描述

請求轉發與重定向的區別

請求轉發的特點:可以攜帶參數,只用一次請求,可以訪問WEB-INF
重定向的特點:可以避免重復扣款場景風險,可以訪問外部網站,不能訪問WEB-INF

請求轉發過程:瀏覽器 - 內部代碼 - WEB-INF
重定向過程:瀏覽器 - 內部代碼 - 瀏覽器 - URL

動態web項目示例:
EServlet

@WebServlet("/go/e")
public class EServlet extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("EServlet");System.out.println("E----扣款1000");//		req.getRequestDispatcher("/go/f").forward(req, resp);
//		resp.sendRedirect("/go/f");
//		resp.sendRedirect("https://www.fu365.com/");//		req.getRequestDispatcher("/WEB-INF/haha.html").forward(req, resp);
//		resp.sendRedirect("/WEB-INF/haha.html");}
}

FServlet

@WebServlet("/go/f")
public class FServlet extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("FServlet");}
}

WEB-INF下新建haha.html
瀏覽器訪問:http://localhost/go/e

用請求轉發和重定向完善登錄

webapp下WEB-INF外新建login.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><form action="/loginTest" method="post">賬號:<input type="text" name="name"><br>密碼:<input type="password" name="password"><input type="submit" value="post"></form>
</body>
</html>

loginTest

@WebServlet("/loginTest")
public class LoginServletTest extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {req.setCharacterEncoding("UTF-8");resp.setContentType("text/html;charset=utf-8");String name = req.getParameter("name");String password = req.getParameter("password");if ( name.equals("zhangsan") && password.equals("123456") ) {resp.sendRedirect("main.html");		//這里在WEB-INF外重定向可以訪問} else {req.setAttribute("msg", "登錄失敗");// 需要訪問另外一個servlet,把參數傳進頁面打印出來req.getRequestDispatcher("/AAAServlet").forward(req, resp);}}
}

main.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><h1>登錄成功</h1>
</body>
</html>

AAAServlet

@WebServlet("/AAAServlet")
public class AAAServlet  extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {Object attribute = req.getAttribute("msg");System.out.println(attribute);PrintWriter writer = resp.getWriter();writer.print("<!DOCTYPE html>");writer.print("<html>");writer.print("<head>");writer.print("<meta charset=\"UTF-8\">");writer.print("<title>Insert title here</title>");writer.print("</head>");writer.print("<body>");writer.print(attribute);writer.print("   <form action=\"/loginTest\" method=\"post\">");writer.print("     賬號:<input type=\"text\" name=\"username\"><br>");writer.print("     密碼:<input type=\"password\" name=\"password\"><br>");writer.print("     <input type=\"submit\" value=\"post\">");writer.print("   </form>");writer.print("</body>");writer.print("</html>");}
}

JSP

第一個JSP
概述

servlet:是用來寫java代碼的,也可以用來做頁面展示(把html代碼一行一行打印出去),但是不擅長做頁面展示。
html:用來做頁面展示,靜態網頁,沒辦法拿到Java代碼,不能展示數據。
jsp:看起來像html,但是它里面可以寫java代碼(動態網頁)。

注釋

webapp下新建_01hello.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><!-- 不安全的注釋,能在控制臺看到 --><%-- 安全的注釋,不能再控制臺看到 --%><h1>我是第一個JSP</h1>
</body>
</html>
設置創建JSP文件默認字符編碼集

JSP文件內右鍵 - Preferences - utf-8

JSP的java代碼書寫
<%@ 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寫java代碼的第一種方式,打印到后端控制臺 --><%for(int i = 0;i<5;i++){System.out.println("i: "+i);}int b =520;%><!-- jsp寫java代碼的第二種方式,顯示在頁面上 --><%=b %><!-- jsp寫java代碼的第三種方式,涉及JSP的底層原理 --><%!String ss ="abc";// System.out.println("abc: "+ss);%></body>
</html>
JSP的原理

jsp需要tomcat運行才能正常展示內容
在這里插入圖片描述
訪問JSP - tomcat的web.xml - 兩個servlet類(把JSP轉化為servlet/java文件,把html代碼打印出去)

tips:tomcat的web.xml是全局的,項目中的web.xml是局部的

三大指令

1.page :當前頁面的一些配置,jsp生成java文件時會引用這些配置

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

2.taglib:不講 (下一節來說 )

3.include:引用一個文件,常用于導航欄
在這里插入圖片描述
_03include.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@include file="head.jsp" %>
<!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><div>螺旋丸</div>
</body>
</html>

_04include.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><div>千年殺</div><%@include file="head.jsp" %>
</body>
</html>

head.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><div style="background-color:red;text-align:center;font-size:50px">火影忍者</div>
九大內置對象
改造動態web工程進行示例

改造LoginServletTest,登錄失敗后跳轉到login.jsp

@WebServlet("/loginTest")
public class LoginServletTest extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {req.setCharacterEncoding("UTF-8");resp.setContentType("text/html;charset=utf-8");String name = req.getParameter("name");String password = req.getParameter("password");if ( name.equals("zhangsan") && password.equals("123456") ) {resp.sendRedirect("main.html");		//這里在WEB-INF外重定向可以訪問} else {req.setAttribute("msg", "登錄失敗");// 需要訪問另外一個servlet,把參數傳進頁面打印出來
//			req.getRequestDispatcher("/AAAServlet").forward(req, resp);req.getRequestDispatcher("login.jsp").forward(req, resp);}}
}

webapp下新增login.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><%=request.getAttribute("msg") %><form action="/loginTest" method="post">賬號:<input type="text" name="name"><br>密碼:<input type="password" name="password"><input type="submit" value="post"></form>
</body>
</html>
內置對象名稱來源?

來自tomcat根據jsp生成的java文件,在那里面定義了
在這里插入圖片描述

名單列表
HttpServletRequest    request  		請求對象    
HttpServletResponse   response 		響應對象
ServletConfig         config      	配置對象
ServletContext      application  
Throwable          	 exception   	異常( 你當前頁面是錯誤頁時才有 isErrorPage="true" )
JspWriter         		out    		輸出流對象
Object           		page   		相當于this 是當前頁的意思
PageContext         pageContext  	沒好大用處 
HttpSession           session  		會話對象(重要)
四大作用域
概述
HttpServletRequest  request    一次請求
HttpSession       session      一次會話	同一個瀏覽器訪問tomcat就是一次會話
PageContext    pageContext    	當前頁面	作用不大
ServletContext   application     整個會話tomcat沒有關閉就不會消失,在不同的瀏覽器都能拿到

在這里插入圖片描述

案例測試

webapp下新增_05page.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><%pageContext.setAttribute("iampageContext","我是當前頁對象");request.setAttribute("iamrequest", "我是請求對象");session.setAttribute("iamsession", "我是會話對象");application.setAttribute("iamapplication", "我是應用對象");%><%=pageContext.getAttribute("iampageContext")%><%=request.getAttribute("iamrequest")%><%=session.getAttribute("iamsession")%>	<%=application.getAttribute("iamapplication")%>
</body>
</html>

webapp下新增_06page.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><%=pageContext.getAttribute("iampageContext")%><%=request.getAttribute("iamrequest")%><%=session.getAttribute("iamsession")%>	<%=application.getAttribute("iamapplication")%>
</body>
</html>

啟動tomcat,瀏覽器訪問http://localhost/_05page.jsp,我是當前頁對象 我是請求對象 我是會話對象 我是應用對象

瀏覽器訪問http://localhost/_06page.jsp,null null 我是會話對象 我是應用對象

換一個瀏覽器訪問http://localhost/_06page.jsp,null null null 我是應用對象

重啟原瀏覽器訪問http://localhost/_06page.jsp,null null null 我是應用對象

重啟tomcat訪問http://localhost/_06page.jsp,null null null null

修改_05page.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><%pageContext.setAttribute("iampageContext","我是當前頁對象");request.setAttribute("iamrequest", "我是請求對象");session.setAttribute("iamsession", "我是會話對象");application.setAttribute("iamapplication", "我是應用對象");%><%request.getRequestDispatcher("_06page.jsp").forward(request, response);%>
</body>
</html>

啟動tomcat,瀏覽器訪問http://localhost/_05page.jsp,null 我是請求對象 我是會話對象 我是應用對象

修改_05page.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><%pageContext.setAttribute("iampageContext","我是當前頁對象");request.setAttribute("iamrequest", "我是請求對象");session.setAttribute("iamsession", "我是會話對象");application.setAttribute("iamapplication", "我是應用對象");%><%//request.getRequestDispatcher("_06page.jsp").forward(request, response);response.sendRedirect("_06page.jsp");%>
</body>
</html>

啟動tomcat,瀏覽器訪問http://localhost/_05page.jsp,null null 我是會話對象 我是應用對象

修改_06page.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><%=pageContext.getAttribute("iampageContext")%><%=request.getAttribute("iamrequest")%><%=session.getAttribute("iamsession")%>	<%=application.getAttribute("iamapplication")%><%request.getRequestDispatcher("_05page.jsp").forward(request, response);%>
</body>
</html>

啟動tomcat,瀏覽器訪問http://localhost/_05page.jsp,報錯:該網頁無法正常運作,localhost將您重定向的次數過多。

登錄完善

改造login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" isErrorPage="true" %>
<!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><%if(request.getAttribute("msg")!=null){ %><%=request.getAttribute("msg") %><%} %><form action="/loginTest" method="post">賬號:<input type="text" name="name"><br>密碼:<input type="password" name="password"><input type="submit" value="post"></form>
</body>
</html>

LoginServletTest設置數據到session作用域

@WebServlet("/loginTest")
public class LoginServletTest extends HttpServlet{@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {ServletContext servletContext = req.getServletContext();HttpSession session = req.getSession();req.setCharacterEncoding("UTF-8");resp.setContentType("text/html;charset=utf-8");String name = req.getParameter("name");String password = req.getParameter("password");if ( name.equals("zhangsan") && password.equals("123456") ) {session.setAttribute("name", "zhangsan");resp.sendRedirect("main.jsp");		//這里在WEB-INF外重定向可以訪問} else {req.setAttribute("msg", "登錄失敗");// 需要訪問另外一個servlet,把參數傳進頁面打印出來
//			req.getRequestDispatcher("/AAAServlet").forward(req, resp);req.getRequestDispatcher("login.jsp").forward(req, resp);}}
}

新建main.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>
恭喜你登錄成功<%=session.getAttribute("name")%>
</body>
</html>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/165151.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/165151.shtml
英文地址,請注明出處:http://en.pswp.cn/news/165151.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

2.HTML入門

目錄 一.HTML介紹 二.HTML常用標簽 2.1 標題標簽 2.2 段落標簽 2.3 超鏈接標簽 2.4 圖片標簽 2.5 換行與空格 2.6 布局標簽 2.7 列表標簽 2.8 表單標簽 一.HTML介紹 定義&#xff1a;將內容顯示在網頁&#xff0c;用來描述網頁的一種語言&#xff0c;負責網頁的架構…

Adiponectin 脂聯素 ; T-cadherin +exosome

T-cadherin Adiponectin exosome T-cadherin Adiponectin exosome 代謝綜合征中 外泌體、脂肪組織 和 脂聯素 的器官間通訊-2019.pdf

【華為OD】C卷真題 100%通過:數組去重和排序 C/C++實現

華為OD 數組去重和排序 C源碼實現&#xff0c;100%通過 目錄 題目描述&#xff1a; 示例1 代碼實現&#xff1a; 題目描述&#xff1a; 給定一個亂序的數組&#xff0c;刪除所有的重復元素&#xff0c;使得每個元素只出現一次&#xff0c;并且按照出現的次數從高到低進行排…

C語言之字符串函數

C語言之字符串函數 文章目錄 C語言之字符串函數1. strlen的使用和模擬實現1.1 strlen的使用1.2 strlen的模擬實現 2. strcpy的使用和模擬實現2.1 strcpy的使用2.2 strncpy的使用2.3 strcpy的模擬實現 3. strcat的使用和模擬實現3.1 strcat的使用3.2 strncat3.3 strcat的模擬實現…

C語言--每日五道選擇題--Day23

第一題 1. 已知int i1, j2;&#xff0c;則表達式ij的值為&#xff08; &#xff09; A&#xff1a;1 B&#xff1a;2 C&#xff1a;3 D&#xff1a;4 答案及解析 C 本題考查的是前置和后置的優先級&#xff0c;后置的優先級是高于前置的&#xff0c;所以這個表達式就可以轉變為…

【Spark源碼分析】事件總線機制分析

Spark事件總線機制 采用Spark2.11源碼&#xff0c;以下類或方法被DeveloperApi注解額部分&#xff0c;可能出現不同版本不同實現的情況。 Spark中的事件總線用于接受事件并提交到對應的監聽器中。事件總線在Spark應用啟動時&#xff0c;會在SparkContext中激活spark運行的事件總…

什么是持續集成的自動化測試?

持續集成的自動化測試 如今互聯網軟件的開發、測試和發布&#xff0c;已經形成了一套非常標準的流程&#xff0c;最重要的組成部分就是持續集成&#xff08;Continuous integration&#xff0c;簡稱CI&#xff0c;目前主要的持續集成系統是Jenkins&#xff09;。 那么什么是持…

docker 安裝常用環境

一、 安裝linux&#xff08;完整&#xff09; 目前為止docker hub 還是被封著&#xff0c;用阿里云、騰訊云鏡像找一找版本直接查就行 默認使用latest最新版 #:latest 可以不寫 docker pull centos:latest # 拉取后查看 images docker images #給鏡像設置標簽 # docker tag […

FIB表與快速轉發表工作原理

在一張路由表中&#xff0c;當存在多個路由項可同時匹配目的IP地址時&#xff0c;路由查找進程會選擇掩碼最長的路由項用于轉發&#xff0c;即最長匹配原則。因為掩碼越長&#xff0c;所處的網段范圍就越小&#xff0c;網段的范圍越小&#xff0c;就越能快速的定位到PC機的具體…

【分布式】小白看Ring算法 - 03

相關系列 【分布式】NCCL部署與測試 - 01 【分布式】入門級NCCL多機并行實踐 - 02 【分布式】小白看Ring算法 - 03 【分布式】大模型分布式訓練入門與實踐 - 04 概述 NCCL&#xff08;NVIDIA Collective Communications Library&#xff09;是由NVIDIA開發的一種用于多GPU間…

通過 python 腳本遷移 Redis 數據

背景 需求&#xff1a;需要將的 Redis 數據遷移由云廠商 A 遷移至云廠商 B問題&#xff1a;云版本的 Redis 版本不支持 SYNC、MIGRATE、BGSAVE 等命令&#xff0c;使得許多工具用不了&#xff08;如 redis-port&#xff09; 思路 &#xff08;1&#xff09;從 Redis A 獲取所…

GoLand 2023.2.5(GO語言集成開發工具環境)

GoLand是一款專門為Go語言開發者打造的集成開發環境&#xff08;IDE&#xff09;。它能夠提供一系列功能&#xff0c;如代碼自動完成、語法高亮、代碼格式化、代碼重構、代碼調試等等&#xff0c;使編寫代碼更加高效和舒適。 GoLand的特點包括&#xff1a; 1. 智能代碼補全&a…

json 去除特殊字符換行等符號

由于字符串中有出現了 換行符&#xff0c;導致轉json失敗&#xff0c;報錯&#xff1a;json parse error。 一般來講&#xff0c;直接用string的replace方法就可以了 String str "{\"adrdet\":\"阿歌嘎\n嘎、\",\"date\":\"2023/06/…

Ubuntu安裝CUDA驅動

Ubuntu安裝CUDA驅動 前言官網安裝確認安裝版本安裝CUDA Toolkit 前言 CUDA驅動一般指CUDA Toolkit&#xff0c;可通過Nvidia官網下載安裝。本文介紹安裝方法。 官網 CUDA Toolkit 最新版&#xff1a;CUDA Toolkit Downloads | NVIDIA Developer CUDA Toolkit 最新版文檔&…

NX二次開發UF_CAM_update_list_object_customization 函數介紹

文章作者&#xff1a;里海 來源網站&#xff1a;https://blog.csdn.net/WangPaiFeiXingYuan UF_CAM_update_list_object_customization Defined in: uf_cam.h int UF_CAM_update_list_object_customization(tag_t * object_tags ) overview 概述 This function provids the…

UDP客戶端使用connect與UDP服務器使用send函數和recv函數收發數據

服務器代碼編譯運行 服務器udpconnectToServer.c的代碼如下&#xff1a; #include<stdio.h> #include<stdlib.h> #include<string.h> #include<unistd.h> #include<arpa/inet.h> #include<sys/socket.h> #include<errno.h> #inclu…

Okhttp 淺析

安全的連接 OkHttpClient: OkHttpClient: 1.線程調度 2.連接池,有則復用,沒有就創建 3.interceptor 4.interceptor 5.監聽工廠 6.是否失敗重試 7.自動修正訪問,如果沒有權限或認證 8是否重定向 followRedirects 9.協議切換時候是否繼續重定向 10.Cookie jar 容器 默認…

Python 的 socket 模塊套接字編程(簡單入門級別)

Python 的 socket 模塊提供了對套接字編程的支持&#xff0c;允許你在網絡上進行數據傳輸。套接字是一個抽象的概念&#xff0c;它允許程序在網絡中的不同節點之間進行通信。 下面是 socket 模塊中一些常用的函數和類&#xff1a; 1. 創建套接字&#xff1a; socket.socket(…

pycharm 創建的django目錄和命令行創建的django再使用pycharm打開的目錄對比截圖 及相關

pytcharm創建django的項目 命令行創建的django 命令行創建項目時 不帶路徑時 (.venv) D:\gbCode>django-admin startproject gbCode 命令行創建項目時 帶路徑時 -- 所以如果有目錄就指定路徑好 (.venv) D:\gbCode>django-admin startproject gbCode d:\gbCode\

洛谷P1219 [USACO1.5] 八皇后【n皇后問題】【深搜+回溯 經典題】【附O(1)方法】

P1219 [USACO1.5] 八皇后 Checker Challenge 前言題目題目描述輸入格式輸出格式樣例 #1樣例輸入 #1樣例輸出 #1 提示題目分析注意事項 代碼深搜回溯打表 后話額外測試用例樣例輸入 #2樣例輸出 #2 王婆賣瓜 題目來源 前言 也是說到做到&#xff0c;來做搜索的題&#xff08;雖…