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

// 设置英语语言代码
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>");
}
}

版权声明:本文为huangyu2579原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/huangyu2579/p/13413436.html