返回网页

6.12.1.无标签网页

  @RequestPath(value = "/plain")
  public HttpResponse plain(String before, String end, HttpRequest request) throws Exception {
    String bodyString = request.getBodyString();
    HttpResponse ret = Resps.html(request, bodyString);
    return ret;
  }

这段代码定义了一个名为 plain 的方法,通过 @RequestPath 注解映射到 /plain URL 路径。这个方法接收三个参数:两个字符串 beforeend,以及一个 HttpRequest 对象 request

  • 方法内部首先调用 request.getBodyString() 方法获取 HTTP 请求的正文(body)内容,存储在 bodyString 变量中。
  • 然后,使用 Resps.html 方法创建一个 HttpResponse 对象,将 bodyString 作为响应内容。

这个方法的主要作用是接收 HTTP 请求,获取请求的正文内容,并将这个内容以 HTML 响应格式返回。虽然方法名为 plain,实际上它以 HTML 格式返回请求的正文内容。

6.12.2.有标签网页

  @RequestPath(value = "/html")
  public HttpResponse html(HttpRequest request) throws Exception {
    HttpResponse ret = Resps.html(request, html);
    return ret;
  }

这段代码定义了一个名为 html 的方法,它通过 @RequestPath 注解映射到 /html URL 路径。这个方法接收一个 HttpRequest 对象作为参数,并执行以下操作:

  • 使用 Resps.html 方法创建一个 HttpResponse 对象。这个方法将生成一个包含 html 内容的 HTTP 响应。
  • html 变量应该是一个包含 HTML 内容的字符串,但代码中没有显示其定义,可能是在方法外部定义的。

该方法的主要作用是当接收到特定的 HTTP 请求时,返回一个包含 HTML 内容的响应。