### Get Git Command Help
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/developer-tools/Git应用.md
These commands provide detailed help and documentation for specific Git commands, explaining their usage, options, and examples directly in the command line.
```Git
git help commit
```
```Git
git commit --help
```
--------------------------------
### Java Servlet Example with @WebServlet Annotation
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Java-Web/Servlet基础.md
Demonstrates a basic Java Servlet (HiServlet) configured using the @WebServlet annotation. It specifies multiple URL patterns (/hi, /hello, *.haha) and sets loadOnStartup to 0, ensuring the Servlet is initialized when the application starts. Includes init, doPost, and doGet methods.
```Java
package com.mylifes1110.java;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* value定义了多个url路径:value = {"/hi", "/hello", "*.haha"}
* Servlet的创建时机设置为:loadOnStartup = 0(启动程序时创建并初始化)
*/
@WebServlet(name = "HiServlet", value = {"/hi", "/hello", "*.haha"}, loadOnStartup = 0)
public class HiServlet extends HttpServlet {
@Override
public void init() throws ServletException {
System.out.println("初始化方法");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("你又被访问到了!哈哈!");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
}
```
--------------------------------
### Tomcat Directory Structure Overview
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Server/tomact服务器基础和开发步骤.md
Provides a table detailing the purpose of each main directory within a Tomcat installation, such as bin, conf, lib, webapps, and work.
```APIDOC
Directory Name | Description
-------------------- | ------------------------------------------------------------
bin | Stores Tomcat executable files, e.g., startup.bat (to start the service)
conf | Tomcat configuration files, e.g., server.xml
lib | Core JAR packages that Tomcat relies on at runtime, e.g., jsp-api.jar, servlet-api.jar
logs | Stores Tomcat execution logs
temp | Stores temporary files
webapps | Stores deployed Web resources
work | Stores Java files after JSP translation
```
--------------------------------
### SQL Physical Pagination Examples with LIMIT
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Java-Web/JSP.md
These SQL examples illustrate how to fetch data for different pages using the `LIMIT` clause. It shows how the starting index changes for subsequent pages when retrieving 10 records per page from an `employee` table. The starting index is 0-based.
```SQL
-- 第一页显示第一个10条数据(查询10条);开始索引为0
-- 从索引为0的数据开始,向后查10条数据
SELECT * FROM employee LIMIT 0 , 10;
-- 第二页显示从第11条数据开始到第20条;开始索引为10
SELECT * FROM employee LIMIT 10 , 10;
-- 第三页显示从第21条数据开始到第30条;开始索引为20
SELECT * FROM employee LIMIT 20 , 10;
-- 第四页显示从第31条数据开始到第40条;开始索引为30
SELECT * FROM employee LIMIT 30 , 10;
```
--------------------------------
### Example HTTP GET Request Line
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Computer-Networks/HTTP网络协议.md
Illustrates a basic HTTP GET request line, specifying the resource path and HTTP protocol version used by the client.
```HTTP
GET /sample/hello.html HTTP/1.1
```
--------------------------------
### Complete JDBC Example for Inserting Data
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Java-Web/JDBC数据库连接.md
A comprehensive Java example demonstrating all six core JDBC steps for performing an INSERT operation. It includes loading the driver, establishing a connection, creating a statement, executing SQL, processing results, and closing resources.
```Java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class TestInsert {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//1.加载驱动,将驱动字节码文件加载到JVM中
Class.forName("com.mysql.jdbc.Driver");
//2.连接数据库
String url = "jdbc:mysql://localhost:3306/companydb?useUnicode=true&characterEncoding=utf8";//数据库连接地址
String user = "root";//用户名
String password = "123456";//密码
Connection connection = DriverManager.getConnection(url, user, password);
//3.获取发送SQL语句的对象
Statement statement = connection.createStatement();
//4.编写SQL语句,并执行SQL语句
String sql = "insert into user (userName, password, address, phone) values ('Ziph', '123456', '河北', '11111111111')";
int result = statement.executeUpdate(sql);
//5.处理结果
if (result > 0) {
System.out.println("添加成功!");
} else {
System.out.println("添加失败!");
}
//6.释放资源,先开后关
statement.close();
connection.close();
}
}
```
--------------------------------
### HTML Image Tag Usage Example
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Frontend-Development/HTML和CSS基础.md
Provides examples of using the `` tag with various attributes like `src`, `width`, `height`, `border`, `alt`, and `title` to display images and provide fallback/hover text.
```HTML
```
--------------------------------
### HTTP Client Request Message Structure and Example
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Computer-Networks/HTTP网络协议.md
Illustrates the four components of an HTTP client request message: request line, headers, empty line, and request body. Includes a concrete example of a POST request.
```APIDOC
POST/hello HTTP/1.1
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Language:zh-CN,zh;q=0.8,en-GB;q=0.6,en;q=0.4
Connection:Keep-Alive
Host:localhost:8080
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/59.0.3071.115 Safari/537.36
Accept-Encoding:gzip, deflate, br
username=zhangsan&age=20&add=beijing
```
--------------------------------
### Check Git Version
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/developer-tools/Git应用.md
This command is used to display the currently installed Git version on your system, confirming that Git is properly installed and accessible.
```Git
git version
```
--------------------------------
### JSP Examples for JSTL Core Tags
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Java-Web/JSP.md
Practical JSP examples demonstrating the usage of various JSTL core tags including c:set for variable assignment, c:remove for variable deletion, c:catch for exception handling, c:if for conditional logic, c:forEach for looping through collections and ranges, and c:forTokens for string tokenization.
```JSP
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
* 由 servlet 容器调用,以允许 servlet 响应某个请求。 * 此方法仅在 servlet 的 init() 方法成功完成之后调用。 * 应该为抛出或发送错误的 servlet 设置响应的状态代码。 * * @param servletRequest 包含客户端请求的 ServletRequest 对象 * @param servletResponse 包含 servlet 的响应的 ServletResponse 对象 * @throws ServletException 如果发生妨碍 servlet 正常操作的异常 * @throws IOException 果发生输入或输出异常 */ @Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { //请求相关内容 ServletRequest ; 相应相关内容 ServletResponse /** * 在控制台内打印输出 */ System.out.println("这是我的第一个Servlet!"); /** * 利用输出流输出系统时间,在浏览器中显示 */ PrintWriter printWriter = servletResponse.getWriter(); Date date = new Date(); printWriter.println(date); printWriter.close(); /** * 利用流输出信息在浏览器内显示 * 解决浏览器显示乱码问题 */ servletResponse.setContentType("text/html;charset=utf-8"); servletResponse.getWriter().println("这是我的第一个Servlet"); } /** * 返回有关 servlet 的信息,比如作者、版本和版权。 *
* 此方法返回的字符串应该是纯文本,不应该是任何种类的标记(比如 HTML、XML,等等)。 * * @return 包含 servlet 信息的 String */ @Override public String getServletInfo() { return null; } /** * 销毁(清除所有资源) *
* 由 servlet 容器调用,指示将从服务中取出该 servlet。
* 此方法仅在 servlet 的 service 方法已退出或者在过了超时期之后调用一次。
* 在调用此方法之后,servlet 容器不会再对此 servlet 调用 service 方法。
* 此方法为 servlet 提供了一个清除持有的所有资源(比如内存、文件句柄和线程)的机会,并确保任何持久状态都与内存中该 servlet 的当前状态保持同步。
*/
@Override
public void destroy() {
}
}
```
--------------------------------
### Java `File` Class Basic Operations Example
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Java-Standard-Edition/JavaIO流.md
This Java code demonstrates various common operations of the `java.io.File` class, including checking file properties (read, write, execute permissions, existence), creating and deleting files, getting paths, names, sizes, and last modified times. It also shows how to get disk space information.
```Java
import java.io.File;
import java.io.IOException;
/**
* 因为有些方法之间互相影响,所以就没有注释掉!
* 自己测试的时候记得注意互相影响的方法!
*/
public class TestFiles {
public static void main(String[] args) throws IOException {
File file = new File("Files\\test\\target.txt");
// File file = new File("Files\\test\\newFile");
System.out.println(file.canExecute());//所有可以打开的文件或文件夹
System.out.println(file.canWrite());//能不能修改文件
System.out.println(file.canRead());//能不能执行文件
System.out.println(file.createNewFile());//文件不存在则新建一个文件
System.out.println(file.delete());//如果文件存在,则删除,返回true
file.deleteOnExit();//JVM终止时,执行删除删除文件
System.out.println(file.exists());//测试此抽象路径名表示的文件或目录是否存在
System.out.println(file.getAbsolutePath());//获得绝对路径
System.out.println(file.getPath());//获得相对路径
System.out.println(file.getName());//获得文件名(文件名.后缀)
System.out.println(file.getFreeSpace() / 1024 / 1024 / 1024);//获得磁盘空闲空间容量
System.out.println(file.getTotalSpace() / 1024 / 1024 / 1024);//获得磁盘总空间容量
System.out.println(file.getParent());//指定文件的上一级目录
System.out.println(file.isDirectory());//判断是否为文件夹
System.out.println(file.isFile());//判断是否为文件
System.out.println(file.isHidden());//判断是否为隐藏文件
System.out.println((System.currentTimeMillis() - file.lastModified()) / 1000 / 60);//获取文件最后一次修改时间
System.out.println(file.length());//文件内容的字节
file.mkdirs();//创建一个新目录
}
}
```
--------------------------------
### Configure Default Welcome Pages in web.xml
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Java-Web/Servlet基础.md
Illustrates how to configure a list of default welcome files in web.xml using the
* 由 servlet 容器调用,以允许 servlet 响应某个请求。
* 此方法仅在 servlet 的 init() 方法成功完成之后调用。
* 应该为抛出或发送错误的 servlet 设置响应的状态代码。
*
* @param servletRequest 包含客户端请求的 ServletRequest 对象
* @param servletResponse 包含 servlet 的响应的 ServletResponse 对象
* @throws ServletException 如果发生妨碍 servlet 正常操作的异常
* @throws IOException 果发生输入或输出异常
*/
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
//请求相关内容 ServletRequest ; 相应相关内容 ServletResponse
/**
* 在控制台内打印输出
*/
System.out.println("这是我的第一个Servlet!");
/**
* 利用输出流输出系统时间,在浏览器中显示
*/
PrintWriter printWriter = servletResponse.getWriter();
Date date = new Date();
printWriter.println(date);
printWriter.close();
/**
* 利用流输出信息在浏览器内显示
* 解决浏览器显示乱码问题
*/
servletResponse.setContentType("text/html;charset=utf-8");
servletResponse.getWriter().println("这是我的第一个Servlet");
}
/**
* 返回有关 servlet 的信息,比如作者、版本和版权。
*
* 此方法返回的字符串应该是纯文本,不应该是任何种类的标记(比如 HTML、XML,等等)。
*
* @return 包含 servlet 信息的 String
*/
@Override
public String getServletInfo() {
return null;
}
/**
* 销毁(清除所有资源)
*
* 由 servlet 容器调用,指示将从服务中取出该 servlet。
* 此方法仅在 servlet 的 service 方法已退出或者在过了超时期之后调用一次。
* 在调用此方法之后,servlet 容器不会再对此 servlet 调用 service 方法。
* 此方法为 servlet 提供了一个清除持有的所有资源(比如内存、文件句柄和线程)的机会,并确保任何持久状态都与内存中该 servlet 的当前状态保持同步。
*/
@Override
public void destroy() {
}
}
```
--------------------------------
### Perform an Asynchronous GET Request with Native JavaScript Ajax
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Frontend-Development/Ajax.md
This JavaScript code snippet, embedded within a JSP page, demonstrates how to perform an asynchronous GET request using native XMLHttpRequest. It includes a cross-browser `createXMLHttpRequest` function, sets up an `onreadystatechange` callback to handle the server response, opens a GET connection with URL parameters, and sends the request. The response is parsed as JSON and logged to the console.
```HTML/JSP
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
");
printWriter.println("
");
printWriter.println("");
printWriter.println("");
printWriter.println("");
}
}
```
--------------------------------
### Example QR Code Payment Result Callback JSON Payload
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/project/小米商城/shopping/README.md
This JSON payload is sent to the callback URL after a successful QR code payment. It contains detailed transaction information such as the application ID, merchant ID, transaction ID, the unique order number ('out_trade_no'), the total payment amount ('total_fee'), and the payment result code ('result_code'). The 'type' field indicates the communication method, where 0 signifies page redirection and 1 signifies point-to-point server communication (which may not be usable with localhost addresses).
```json
{
"result":
{
"appid":"wx632c8f211f8122c6",
"bank_type":"CFT",
"cash_fee":"1",
"fee_type":"CNY",
"is_subscribe":"Y",
"mch_id":"1497984412",
"nonce_str":"1631171182",
"openid":"oUuptwrJudIfdihz1Z_T1AciMahs",
"out_trade_no":"1221ea762d54496e83a33c9dab72f320",
"result_code":"SUCCESS",
"return_code":"SUCCESS",
"sign":"5C7314AA4EB21772B42DBBCD65E56ACF",
"time_end":"20180207163125",
"total_fee":"1",
"trade_type":"NATIVE",
"transaction_id":"4200000065201802078895888133"},
"type":0
}
```
--------------------------------
### Configure Servlet in web.xml
Source: https://github.com/ziphtracks/javalearningmanual/blob/master/docs/Java-Web/Servlet基础.md
This XML configuration snippet demonstrates how to register a Servlet and map it to a URL pattern within the `web.xml` deployment descriptor. It defines the Servlet's fully qualified class name using `");
printWriter.println(" ");
for (User user : userList) {
printWriter.println("编号 ");
printWriter.println("用户名 ");
printWriter.println("密码 ");
printWriter.println("手机号 ");
printWriter.println("");
printWriter.println(" ");
}
printWriter.println("");
printWriter.println(user.getId());
printWriter.println(" ");
printWriter.println("");
printWriter.println(user.getUsername());
printWriter.println(" ");
printWriter.println("");
printWriter.println(user.getPassword());
printWriter.println(" ");
printWriter.println("");
printWriter.println(user.getPhone());
printWriter.println(" ");
printWriter.println("