Ordered JSONObject

As JSON objects do not inherently have an order, you should use an array within your JSON object to ensure order. As an example (based on your code): jsonObj = { items: [ { name: “Stack”, time: “…” }, { name: “Overflow”, time: “…” }, { name: “Rocks”, time: “…” }, … ] }; This … Read more

GSON is not being imported into the maven project

Try: <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.1</version> <scope>provided</scope> </dependency> I have edited my comment and added the scope. The default scope is compile, meaning that the dependency is not present at runtime. For this, you use the provided scope. More about scopes in maven dependencies on Apache’s Introduction to Maven Dependencies. Hope this resolves your issue. P.S.: … Read more

How to set the content type on the servlet

What should I set as the content type so that it retains the file extension? Use ServletContext#getMimeType() to get the mime type based on the file name. String mimeType = getServletContext().getMimeType(filename); The servletcontainer usually already provides a default mime type mapping in its own web.xml. If you want to overridde or add some other, then … Read more

How does server prioritize which type of web.xml error page to use?

This is not specific to Tomcat. This is specific to the Servlet API. How the error page is determined is specified in chapter 9.9.2 of Servlet API specification 2.5. Here’s an extract of relevance: SRV.9.9.2 Error Pages If no error-page declaration containing an exception-type fits using the class-hierarchy match, and the exception thrown is a … Read more