设置网页翻译的小技巧

网页翻译:看了网上很多答案都是利用隐藏写多个模块,这里可以利用浏览器来完成网页翻译,通过

// 设置英语语言代码
response.setHeader("Content-Language", "en");给页面设定语言属性,谷歌会跟浏览器语言进行比对,并弹出翻译的按钮
例子:
package Servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.util.Locale;
@WebServlet("/hai")
public class Del extends HttpServlet{

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
// 设置响应内容类型
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// 设置英语语言代码
response.setHeader("Content-Language", "en");

String title = "En Español";
String docType = "<!DOCTYPE html> \n";
/* out.println(docType +
"<html>\n" +
"<head><title>" + title + "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1>" + "En Espa&ntilde;ol:" + "</h1>\n" +
"<h1>" + "&iexcl;Hola Mundo!" + "</h1>\n" +
"</body></html>");*/
out.println(docType +
"<html>\n" +
"<head><title>" + title + "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1>" + "english:" + "</h1>\n" +
"<h1>" + "hello world!" + "</h1>\n" +
"</body></html>");
}
}
posted @ 2020-08-01 09:51  荒毓  阅读(626)  评论(0编辑  收藏  举报