Servlet Maven Dependencies
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency>
Servlet URL Mapping annotation
@WebServlet(name = "ImageUploadCTL", urlPatterns = { "/ImageUploadCTL" })
Image uploading Maven Dependencies
<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.2</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.7</version> </dependency>
While developing a web application using JSP, Servlet, Spring, and hibernate or in Java. there are lots of utilities and methods that are required frequently, In this page, I will cover some of them and will keep updating to cover up as many as solutions.
Get path of your root folder
request.getContextPath()
It will return the base path of the application.
Take a single parameter and return multiple values
String[] values = getParameterValues(“Input Parameter”);
How to encode the URL or Manage Session without cookies
String encode = response.encodeUrl(request.getContextPath()); response.sendRedirect(encode+"welcome.jsp");
How to set a Servlet context
String Url = "<a herf= 'codebun.com'>Home</a>"; ServletContext context = getServletContext(); context.setAttribute("url", Url);
get a servlet context
${url}
Send Bean Object from Servlet to JSP
request.setAttribute("bean", bean);
Get bean Object in JSP from Servlet
<jsp:useBean id="bean" class="com.travelandtour.beans.UserBean" scope="request"></jsp:useBean>