<%@ include file=” ”%> ——最简洁易懂的解释

本文介绍了如何在JSP页面中使用<%@ include %>指令来引入另一个JSP文件,并展示了正确的编码设置方法。
<%@ include file=” ”%> 
假如 在B.jsp 中,使用<%@ include file=”A.jsp”%> ,那么就是把 A.jsp 的内容 原封不动  引入到 B.jsp 中。
另外注意编码问题,在 A.jsp 中,必须加入 JSP 头部信息。
实例:
A.jsp:(必须加入JSP头部信息,写明编码,否则乱码)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<TR>
     <TD class="" height="30" width="170">
         <span align="left" id="">客户类型</span>
     </TD>
</TR>
B.jsp:(必须加入JSP头部信息,写明编码,否则乱码)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<TABLE> 
    <%@ include file="A.jsp"  %>
</TABLE> 

引入后的 B.jsp 的实际的结果如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<TABLE> 
<TR>
     <TD class="" height="30" width="170">
         <span align="left" id="">客户类型</span>
     </TD>
</TR>
</TABLE> 
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <pthread.h> #define PORT 8080 // 服务器端口 // 线程处理函数 void *handle_client(void *sock_ptr) { int sock = *(int *)sock_ptr; char buffer[1024] = {0}; // 1. 读取客户端请求 read(sock, buffer, sizeof(buffer)); // 2. 解析请求路径(简化版) char path[256] = "./web"; // 网站根目录 if (strstr(buffer, "GET / ") != NULL) { strcat(path, "/Index.html"); } else if (strstr(buffer, "GET /About.html ") != NULL) { strcat(path, "/About.html"); } else if (strstr(buffer, "GET /Work.html ") != NULL) { strcat(path, "/Work.html"); } else if (strstr(buffer, "GET /Contact.html ") != NULL) { strcat(path, "/Contact.html"); } else { strcat(path, "/Index.html"); // 默认返回首页 } // 3. 打开文件并发送 FILE *file = fopen(path, "rb"); if (file) { // 发送HTTP头 char header[128] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"; write(sock, header, strlen(header)); // char file_buffer[1024]; size_t bytes_read; while ((bytes_read = fread(file_buffer, 1, sizeof(file_buffer), file)) > 0) { write(sock, file_buffer, bytes_read); } fclose (file); } else { // 文件不存在 char not_found[] = "HTTP/1.1 404 Not Found\r\n\r\n<h1>Page Not Found</h1>"; write(sock, not_found, strlen(not_found)); } // 4. 关闭连接 close(sock); free(sock_ptr); return NULL; } int main() { // 1. 创建服务器套接字 int server_fd = socket(AF_INET, SOCK_STREAM, 0); // 2. 设置服务器地址 struct sockaddr_in addr = { .sin_family = AF_INET, .sin_port = htons(PORT), .sin_addr.s_addr = INADDR_ANY}; // 3. 绑定端口 bind(server_fd, (struct sockaddr *)&addr, sizeof(addr)); // 4. 开始监听 listen(server_fd, 10); printf("服务器启动: http://localhost:%d\n", PORT); // 5. 主循环:接受连接 while (1) { int *client_sock = malloc(sizeof(int)); *client_sock = accept(server_fd, NULL, NULL); // 6. 创建线程处理请求 pthread_t thread_id; pthread_create(&thread_id, NULL, handle_client, client_sock); // 7. 分离线程(自动回收资源) pthread_detach(thread_id); } return 0; } 还是会在 write(sock, file_buffer, bytes_read);这个地方出错,你重新写一份初学者写的多进程webserver
最新发布
08-14
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值