设置网页翻译的小技巧
网页翻译:看了网上很多答案都是利用隐藏写多个模块,这里可以利用浏览器来完成网页翻译,通过
// 设置英语语言代码
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ñol:" + "</h1>\n" +
"<h1>" + "¡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>");
}
}