Servlet returns “HTTP Status 404 The requested resource (/servlet) is not available”

Introduction This can have a lot of causes which are broken down in following sections: Put servlet class in a package Set servlet URL in url-pattern @WebServlet works only on Servlet 3.0 or newer javax.servlet.* doesn’t work anymore in Servlet 5.0 or newer Make sure compiled *.class file is present in built WAR Test the … Read more

How can I upload files to a server using JSP/Servlet?

Introduction To browse and select a file for upload you need a HTML <input type=”file”> field in the form. As stated in the HTML specification you have to use the POST method and the enctype attribute of the form has to be set to “multipart/form-data”. <form action=”upload” method=”post” enctype=”multipart/form-data”> <input type=”text” name=”description” /> <input type=”file” … Read more

Why does getAttribute() in HttpServletRequest works for GET method but not for POST method?

You should always use getParameter, when attribute come from GET or POST method. And use getAttribute when request is forwarded from another servlet/jsp. Such as : ServletA: request.setAttribute(“test”,”value”) request.getRequestDispatcher(“/ServletB”).forward(request, response) ServletB: request.getAttribute(“test”) <– you can get test attribute by using getAttribute