Tag: 现场

基于Locale的Jetty重定向

我想基于请求客户端的区域设置 – 重定向Jetty中的URL,服务器端。 即 客户端发出主机请求:port / help / index.html (’help’是webapp war) 服务器端我读取客户端语言环境,例如’ GB ‘并重定向到单独的webapp,例如* host:port / help_GB / index.html * 我认为这将像运行我的Jetty服务器的服务器端代码一样简单: – String i18nID = Locale.getDefault().getCountry(); RewriteHandler rewrite = new RewriteHandler(); rewrite.setRewriteRequestURI(true); rewrite.setRewritePathInfo(false); rewrite.setOriginalPathAttribute(“requestedPath”); RedirectRegexRule r = new RedirectRegexRule(); r.setRegex(“/help/(.*)”); r.setReplacement(“/help_” + i18nID + “/$1”); rewrite.addRule(r); server.setHandler(rewrite); 但这不起作用,我为所有’host:port / *’地址获得404s。 然后我注意到我无论如何都得到了语言环境服务器端,我想要客户端,所以我编写了自己的处理程序: – private class MyHandler […]

隐藏Javainheritance中的字段

在类中,与超类中的字段具有相同名称的字段会隐藏超类的字段。 public class Test { public static void main(String[] args) { Father father = new Son(); System.out.println(father.i); //why 1? System.out.println(father.getI()); //2 System.out.println(father.j); //why 10? System.out.println(father.getJ()); //why 10? System.out.println(); Son son = new Son(); System.out.println(son.i); //2 System.out.println(son.getI()); //2 System.out.println(son.j); //20 System.out.println(son.getJ()); //why 10? } } class Son extends Father { int i = 2; int j […]