网页翻译:看了网上很多答案都是利用隐藏写多个模块,这里可以利用浏览器来完成网页翻译,通过
// 设置英语语言代码
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> ";
/* out.println(docType +
"<html> " +
"<head><title>" + title + "</title></head> " +
"<body bgcolor="#f0f0f0"> " +
"<h1>" + "En Español:" + "</h1> " +
"<h1>" + "¡Hola Mundo!" + "</h1> " +
"</body></html>");*/
out.println(docType +
"<html> " +
"<head><title>" + title + "</title></head> " +
"<body bgcolor="#f0f0f0"> " +
"<h1>" + "english:" + "</h1> " +
"<h1>" + "hello world!" + "</h1> " +
"</body></html>");
}
}