What does request.getParameter return?

// index.jsp <form method=”post” action=”backend.jsp”> <input type=”text” name=”one” /> <input type=”submit value=”Submit” /> </form> In backend.jsp what does request.getParameter(“one”); return? request.getParameter(“one”).getClass().getName(); returns java.lang.String, so it must be a String right? However I cannot do String one = request.getParameter(“one”); if (!””.equals(one)) {} or This is obvious, because variable one does not return null. Is only way … Read more

What is the difference between response.sendRedirect() and request.getRequestDispatcher().forward(request,response)

To simply explain the difference, response.sendRedirect(“login.jsp”); doesn’t prepend the contextpath (refers to the application/module in which the servlet is bundled) but, whereas request.getRequestDispathcer(“login.jsp”).forward(request, response); will prepend the contextpath of the respective application Furthermore, Redirect request is used to redirect to resources to different servers or domains. This transfer of control task is delegated to the browser by … Read more

org.apache.jasper.JasperException: Unable to compile class for JSP:

Hi I’m trying to compile a simple jsp file with tomcat but I kept having this error message org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 13 in the jsp file: /WebContent/test.jsp Member cannot be resolved to a type 10: <body> 11: <% 12: //MyBatisDao myDao = new MyBatisDao(); 13: List<Member> … Read more

How to solve the “failed to lazily initialize a collection of role” Hibernate exception

If you know that you’ll want to see all Comments every time you retrieve a Topic then change your field mapping for comments to: @OneToMany(fetch = FetchType.EAGER, mappedBy = “topic”, cascade = CascadeType.ALL) private Collection<Comment> comments = new LinkedHashSet<Comment>(); Collections are lazy-loaded by default, take a look at this if you want to know more.

What does this expression language ${pageContext.request.contextPath} exactly do in JSP EL?

The pageContext is an implicit object available in JSPs. The EL documentation says The context for the JSP page. Provides access to various objects including:servletContext: …session: …request: …response: … Thus this expression will get the current HttpServletRequest object and get the context path for the current request and append /JSPAddress.jsp to it to create a … Read more

how to fix Cannot call sendRedirect() after the response has been committed?

you have already forwarded the response in catch block: RequestDispatcher dd = request.getRequestDispatcher(“error.jsp”); dd.forward(request, response); so, you can not again call the : response.sendRedirect(“usertaskpage.jsp”); because it is already forwarded (committed). So what you can do is: keep a string to assign where you need to forward the response. String page = “”; try { } … Read more

What is the difference between JSF, Servlet and JSP?

JSP (JavaServer Pages) JSP is a Java view technology running on the server machine which allows you to write template text in client side languages (like HTML, CSS, JavaScript, ect.). JSP supports taglibs, which are backed by pieces of Java code that let you control the page flow or output dynamically. A well-known taglib is JSTL. JSP also supports Expression … Read more