Iterating through the union of several Java Map key sets efficiently

In one of my Java 6 projects I have an array of LinkedHashMap instances as input to a method which has to iterate through all keys (ie through the union of the key sets of all maps) and work with the associated values. Not all keys exist in all maps and the method should not go through each key more than once or alter the input maps. My current implementation looks like this: Set<Object>

有效地迭代几个Java Map键集合的迭代

在我的一个Java 6项目中,我有一个LinkedHashMap实例数组作为要遍历所有键的方法的输入(即通过所有映射的键集的并集)并使用关联的值。 并非所有的键都存在于所有的地图中,并且该方法不应该经过一次以上的每个键或者改变输入地图。 我目前的实现如下所示: Set<Object> keyset = new HashSet<Object>(); for (Map<Object, Object> map : input) { for (Object key : map.keySet()) { if (ke

How to upload files to server using JSP/Servlet?

How can I upload files to server using JSP/Servlet? I tried this: <form action="upload" method="post"> <input type="text" name="description" /> <input type="file" name="file" /> <input type="submit" /> </form> However, I only get the file name, not the file content. When I add enctype="multipart/form-data" to the <form> , then request.

如何使用JSP / Servlet将文件上传到服务器?

我如何使用JSP / Servlet将文件上传到服务器? 我试过这个: <form action="upload" method="post"> <input type="text" name="description" /> <input type="file" name="file" /> <input type="submit" /> </form> 但是,我只获取文件名,而不是文件内容。 当我将enctype="multipart/form-data"到<form> ,则request.getParameter()返回null 。 在研究期间,

How to create a generic array in Java?

Due to the implementation of Java generics, you can't have code like this: public class GenSet<E> { private E a[]; public GenSet() { a = new E[INITIAL_ARRAY_LENGTH]; // error: generic array creation } } How can I implement this while maintaining type safety? I saw a solution on the Java forums that goes like this: import java.lang.reflect.Array; class Stack<

如何在Java中创建通用数组?

由于Java泛型的实现,你不能拥有这样的代码: public class GenSet<E> { private E a[]; public GenSet() { a = new E[INITIAL_ARRAY_LENGTH]; // error: generic array creation } } 我如何在维护类型安全的同时实现这一点? 我在Java论坛上看到了这样一个解决方案: import java.lang.reflect.Array; class Stack<T> { public Stack(Class<T> clazz, int capacity) {

How can I pad an integers with zeros on the left?

How do you left pad an int with zeros in java when converting to a string? I'm basically looking to pad out integers up to 9999 with the leading zeros (eg 1 = "0001"). Use java.lang.String.format(String,Object...) like this: String.format("%05d", yournumber); for zero-padding with a length of 5. For hexadecimal output replace the d with an x as in "%05x" . The full

我怎样才能用左边的零填充整数?

转换为字符串时,如何在java中留下一个int用零填充? 我基本上希望用前导零填充高达9999的整数(例如1 =“0001”)。 像这样使用java.lang.String.format(String,Object...) : String.format("%05d", yournumber); 用于长度为5的零填充。对于十六进制输出,用“ x "%05x"的x代替d 。 完整的格式化选项被记录为java.util.Formatter一部分。 如果您出于任何原因使用pre 1.5 Java,那么可以尝试使用Apache Commons

How to use Servlets and Ajax?

I'm very new to web apps and Servlets and I have the following question: Whenever I print something inside the servlet and call it by the webbrowser, it returns a new page containing that text. Is there a way to print the text in the current page using Ajax? Indeed, the keyword is "ajax": Asynchronous JavaScript and XML. However, last years it's more than often Asynchronou

如何使用Servlets和Ajax?

我对web应用程序和Servlet非常陌生,我有以下问题: 每当我在servlet内部打印一些内容并由webbrowser调用时,它会返回一个包含该文本的新页面。 有没有办法使用Ajax打印当前页面中的文本? 的确,关键字是“ajax”:异步JavaScript和XML。 然而,去年它不止是Asynchronous JavaScript和JSON。 基本上,你让JS执行一个异步HTTP请求,并基于响应数据更新HTML DOM树。 由于在所有浏览器(特别是Internet Explorer与其他浏览

sending HTTP parameters via POST method easily

I am successfully using this code to send HTTP requests with some parameters via GET method void sendRequest(String request) { // i.e.: request = "http://example.com/index.php?param1=a&param2=b&param3=c"; URL url = new URL(request); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setInstanc

通过POST方法轻松发送HTTP参数

我成功使用此代码通过GET方法发送带有一些参数的HTTP请求 void sendRequest(String request) { // i.e.: request = "http://example.com/index.php?param1=a&param2=b&param3=c"; URL url = new URL(request); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setInstanceFollowRedirects(false); connecti

RS response with HTTP status 500 instead of HTTP status 400

Sometimes JAR-RS clients are sending wrong syntactical request body. The server should response with HTTP status 400 (Bad Request), but it responses with HTTP status 500 (Internal Server Error). Code: JAX-B model class: @XmlRootElement(namespace = "http://www.test.com/test") @XmlAccessorType(value = XmlAccessType.FIELD) public class TestModel { @XmlElement private String id; } JAX

RS响应HTTP状态500而不是HTTP状态400

有时JAR-RS客户端发送错误的语法请求体。 服务器应该响应HTTP状态400(错误请求),但它响应HTTP状态500(内部服务器错误)。 码: JAX-B模型类: @XmlRootElement(namespace = "http://www.test.com/test") @XmlAccessorType(value = XmlAccessType.FIELD) public class TestModel { @XmlElement private String id; } JAX-RS资源类: @Path("test") public class TestResource { @POST @Consumes(Med

How do I use the Jersey JSON POJO support?

I have an object that I'd like to serve in JSON as a RESTful resource. I have Jersey's JSON POJO support turned on like so (in web.xml): <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey

我如何使用Jersey JSON POJO支持?

我有一个对象,我想用JSON作为RESTful资源提供服务。 我开启了Jersey的JSON POJO支持(在web.xml中): <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>

Getting MimeType subtype with Apache tika

I'd need to get the iana.org MediaType rather than application/zip or application/x-tika-msoffice for documents like, odt, ppt, pptx, xlsx etc. If you look at mimetypes.xml there are mimeType elements composed of the iana.org mime-type and "sub-class-of" <mime-type type="application/msword"> <alias type="application/vnd.ms-word"/> ..........................

使用Apache tika获取MimeType子类型

我需要获取iana.org MediaType,而不是应用程序/ zip或application / x-tika-msoffice用于像odt,ppt,pptx,xlsx等文档。 如果你看看mimetypes.xml,有mimeType元素由iana.org mime类型和“sub-class-of” <mime-type type="application/msword"> <alias type="application/vnd.ms-word"/> ............................ <glob pattern="*.doc"/> <glob pattern="*.dot"/> <

creating folders in remote repository using jgit

This question already has an answer here: How can I add an empty directory to a Git repository? 28 answers Git does not support adding empty folders to git. So even though you have added it, it is not going to be in the Git index till you add a file. See associated stack overflow question. How can I add an empty directory to a Git repository?

使用jgit在远程存储库中创建文件夹

这个问题在这里已经有了答案: 我如何将一个空目录添加到Git存储库? 28个答案 Git不支持向git添加空文件夹。 所以,即使你添加了它,它也不会在Git索引中,直到你添加一个文件。 查看关联的堆栈溢出问题。 我如何将一个空目录添加到Git存储库?