< meta charset = "UTF-8" > < meta name = "viewport" content = "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" > < title > 首页 </ title > < link rel = "stylesheet" href = "../public/css/typo.css" > < style > body { background-color : #3a4563 ; #login { margin : 230 px auto auto ; /*background: #ffd5d5;*/ width : 250 px ; height : 250 px ; /*border:1px solid green;*/ /*-webkit-border-radius: 4px;*/ /*-moz-border-radius: 4px;*/ /*border-radius: 4px;*/ text-align : center ; #username , #password { padding-left : 8 px ; width : 94 % ; margin-top : 20 px ; height : 30 px ; -webkit-border-radius : 4 px ; -moz-border-radius : 4 px ; border-radius : 4 px ; #button { margin-top : 20 px ; webkit-display : flex ; display : flex ; justify-content : space-around ; #button span { cursor : pointer ; padding : 0 44 px ; display : inline-block ; color : #ffffff ; font-size : 16 px ; line-height : 30 px ; -webkit-border-radius : 4 px ; -moz-border-radius : 4 px ; border-radius : 4 px ; text-decoration : none ; background-color : #667cdf ; </ style > < div id = "login" > < form action = "" > < input id = "username" type = "text" name = "username" placeholder = '请输入用户名' > < input id = "password" type = "password" name = "password" > < div id = "button" > < span class = "login" > 登录 </ span > < span class = "reg" > 注册 </ span > </ div > </ form > </ div > </ body > </ html > < script src = "../public/js/jquery.js" > </ script > < script src = "../public/js/index.js" > </ script >

通过fs.readSynce()方法取到的index.html页面的内容赋值给变量 body
然后:

response.writeHead(200,{'Content-Type':'text/html'});//注意这里的html,如果为plain则不会显示html,会输出.html文件中的字符串
response.write(body);
response.end();

这样运行后会报错:

查看后发现:
这里写图片描述

外联的js和css文件都没有成功返回相应的数据。

这是因为这段代码中规定的’Content-Type’都是’text/html’类型。而css和js也必须得按照相应的Content-Type类型加载才能成功。

另附不同文件对应的不同类型:

    "html" : "text/html",  
    "css"  : "text/css",  
    "js"   : "text/javascript",  
    "json" : "application/json",  
    "ico"  : "image/x-icon",  
    "gif"  : "image/gif",  
    "jpeg" : "image/jpeg",  
    "jpg"  : "image/jpeg",  
    "png"  : "image/png",  
    "pdf"  : "application/pdf",  
    "svg"  : "image/svg+xml",  
    "swf"  : "application/x-shockwave-flash",  
    "tiff" : "image/tiff",  
    "txt"  : "text/plain",  
    "wav"  : "audio/x-wav",  
    "wma"  : "audio/x-ms-wma",  
    "wmv"  : "video/x-ms-wmv",  
    "xml"  : "text/xml" 

既然知道了原因我们应该如何做呢?我们需要搭建一个静态文件处理器,实现加载不同文件按不同的类型来加载。可以参开我的 github 。切换到lesson2分支。static-server文件夹下的static-load-server.js和static-server.js为主要代码。

逻辑描述: nodejs中response.write(html),html中script标签引用了外部的文件是的处理:通过构建一个静态文件服务器来实现,response.write()输出字符串到html页面时,外联文件能顺利访问成功。
HttpServlet Response response = get Response (); response .setHeader("content-type", "text/ html ;charset=UTF-8"); OutputStream out = response .getOutputStream(); out. write (content.getBytes("UTF-8")); out...
1,不跳转 ajax调用后台不会跳转只会返回,最多返回跳转的 页面 付给data参数(@ Response Body,或 response .get Write r(). write ()) response .get Write r(). write (): 1.1 有多个if都有( response .get Write r(). write ())的 候不写return还会继续向下执行,一般用有返回的函数,然后re... chunk                      是一个buffer 或 字符 串,表示发送的内容 encoding                如果chunk是 字符 串,就需要 指定 encoding来说明它的编码方式,默认utf-8 代码如下: var http = require(‘http’); http.createServer(function 接收参数: data                           end()执行完毕后要 输出 字符 ,如果 指定 了 data 的值,那就意味着在执行完 response .end() 之后,会接着执行一条 response . write (data , encoding); encoding                  对应data的 字符 编码
本文实例讲述了C#中图片、二进制与 字符 串的相互转换 方法 。分享给大家供大家参考,具体如下: protected void Button1_Click(object sender, EventArgs e) //图片转二进制 byte[] imageByte = GetPictureData(Server.MapPath(./uploadfile/111.png)); //二进制转换成 字符 串 string picStr = Convert.ToBase64String(imageByte); // 输出 字符 Response . Write (picStr); Print Write r get Write r() 获得 字符 流,通过 字符 流的 write (String s) 方法 可以将 字符 串设置到 response 缓冲区中,随后Tomcat会将 response 缓冲区中的内容组装成Http响应返回给浏览 器端。 关于设置中文的乱码 问题 原因: response 缓冲区的默认编码是iso8859-1,此码表中...
本文实例讲述了C#实现将 字符 串转换成日期格式的 方法 。分享给大家供大家参考。具体实现 方法 如下: 代码如下:string s = “20120114161145”; Response . Write (DateTime.ParseExact(s, “yyyyMMddHHmmss”, new System.Globalization.CultureInfo(“zh-CN”, true)).ToString()); return; 希望本文所述对大家的C#程序设计有所帮助。 您可能感兴趣的文章:C#中判断、验证 字符 串是否为日期格式的实现代码C# string
RESPONSE . WRITE 与<%=%>都是ASP程序向客户端 输出 字符 串的 方法 ,虽然两者的结果相同但是其效果是不同的。 一般的来说我们大部分 间将<%=%>用于 html 与asp代码相混合的状态下,而 Response . Write 用于〈%……%〉脚本段中,但从VBScript 语法 <% = expression %> 将“表达式”的值写入 ASP 输出 流来分析这个 方法 可以发现。如果响应缓冲没有打开,则这些语句的每一句都会导致通过网络,以许多小型包的形式,向浏览器写入数据。这是非常慢的。另外,解释少量脚本和 HTML ,将导致在脚本引擎和 HTML 之间切换,也降低了性能。因此,对于 Respons
response .get write r(). write () 是一个Java Servlet中的 方法 ,用于以 字符 方式写入响应数据。具体操作是获取响应对象 response 输出 流,并用get Write r() 方法 返回Print Write r对象,最后调用 write () 方法 输出 流中写入 字符 数据。这些 字符 数据将被发送到客户端浏览器中显示。该 方法 常用于动态生成 HTML 代码、XML或JSON等格式的响应数据。 在使用该 方法 需要注意以下几点: 1. 该 方法 必须在响应头中设置content-type属性, 指定 字符 编码方式,否则可能会引起乱码。 2. 由于该 方法 一次只能写入一个 字符 序列,因此需要循环调用 write () 方法 ,以便将完整的响应数据写入 输出 流中。 3. 最后需要调用flush() 方法 ,将 输出 流中的数据刷新(缓存数据写入到网络中),以确保客户端能够正常接收到响应数据。 此外,为了提高响应速度和性能,可以使用缓存响应数据的方式,例如使用StringBuffer或StringBuilder类来缓存生成的响应数据,最终再将缓存的数据一次性写入 输出 流中,而不是每次写入一个 字符 序列。
guolingege: ndy:***** *****$ npm i puppeteer --ignore-scripts npm ERR! Cannot read properties of null (reading 'pickAlgorithm') npm ERR! A complete log of this run can be found in: npm ERR! /Users/sunguolin/.npm/_logs/2022-06-23T09_22_37_033Z-debug-0.log js中!!()的作用 var a = '111' + 0; 这个结果也是string类型,而不是数值型 git stash pop后出现冲突 weixin_41811424: git stash pop后出现冲突 祖安狂人学编程: 还好我先看了评论 表情包