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 much 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>