java.util.MissingResourceException: Can’t find bundle for base name javax.servlet.LocalStrings, locale es_ES

Caused by: java.util.MissingResourceException: Can’t find bundle for base name javax.servlet.LocalStrings, locale es_ES That’s the real error. Your running tests are missing the servlet-api dependency. If you’re using maven make sure this dependency is in your project: <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency>

Send error message as JSON object

From the HttpServletResponse#sendError() javadoc: The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to “text/html”, leaving cookies and other headers unmodified. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will … Read more

how to get the base url from jsp request object?

So, you want the base URL? You can get it in a servlet as follows: String url = request.getRequestURL().toString(); String baseURL = url.substring(0, url.length() – request.getRequestURI().length()) + request.getContextPath() + “/”; // … Or in a JSP, as <base>, with little help of JSTL: <%@taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %> <%@taglib prefix=”fn” uri=”http://java.sun.com/jsp/jstl/functions” %> <c:set var=”req” value=”${pageContext.request}” /> … Read more

Multiple submit buttons in the same form calling different Servlets

There are several ways to achieve this. Probably the easiest would be to use JavaScript to change the form’s action. <input type=”submit” value=”SecondServlet” onclick=”form.action=’SecondServlet’;”> But this of course won’t work when the enduser has JS disabled (mobile browsers, screenreaders, etc). Another way is to put the second button in a different form, which may or … Read more

How can I get MIME type of an InputStream of a file that is being uploaded?

I wrote my own content-type detector for a byte[] because the libraries above weren’t suitable or I didn’t have access to them. Hopefully this helps someone out. // retrieve file as byte[] byte[] b = odHit.retrieve( “” ); // copy top 32 bytes and pass to the guessMimeType(byte[]) funciton byte[] topOfStream = new byte[32]; System.arraycopy(b, … Read more

Java EE 6: JSF vs Servlet + JSP. Should I bother learning JSF?

JSF basically enables you to develop a web application with only model objects (JavaBeans) and views (JSP/XHTML pages). With “plain vanilla” JSP/Servlet you’ll have to bring in a lot of code to control, preprocess, postprocess, gather data, validate, convert, listen, etc the HTTP request and response. And then I’m not talking about refactoring it to … Read more

How to add filters to servlet without modifying web.xml

Just do the same job as the container already does. I.e. reinvent the wheel of the chain of responsibility design pattern as is under the covers been used by servlet filters. public class GodFilter implements Filter { private Map<Pattern, Filter> filters = new LinkedHashMap<Pattern, Filter>(); @Override public void init(FilterConfig config) throws ServletException { Filter1 filter1 … Read more

difference between a valve and a filter

From Tomcat documentation: A Valve element represents a component that will be inserted into the request processing pipeline for the associated Catalina container The servlet filters serve the exact same purpose, but valves are Tomcat’s specific classes, tightly coupled to Tomcat infrastructure/API. On the other hand servlet API is implemented by all compatible web containers. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)