Why does getRealPath() return null when deployed with a .war file? [duplicate]

For a start, ServletRequest.getRealPath(String path) is deprecated. The appropriate replacement is: ServletContext context = session.getServletContext(); String realContextPath = context.getRealPath(request.getContextPath()); However, the API docs for ServletContext.getRealPath(String path) state: “This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made … Read more

View all fields / properties of bean in JSP / JSTL

Replace object with the bean to determine. <c:set var=”object” value=”${product}” /> Display all declared fields and their values. <c:if test=”${not empty object[‘class’].declaredFields}”> <h2>Declared fields <em>&dollar;{object.name}</em></h2> <ul> <c:forEach var=”field” items=”${object[‘class’].declaredFields}”> <c:catch><li><span style=”font-weight: bold”> ${field.name}: </span>${object[field.name]}</li> </c:catch> </c:forEach> </ul> </c:if> Display all declared methods. <c:if test=”${not empty object[‘class’].declaredMethods}”> <h2>Declared methods<em>&lt;% object.getName() %&gt;</em></h2> <ul> <c:forEach var=”method” items=”${object[‘class’].declaredMethods}”> <c:catch><li>${method.name}</li></c:catch> … Read more

How to obtain request / session / servletcontext attribute in JSP using EL?

It’s just the attribute name as you’ve set yourself here: request.setAttribute(“list”, fooList); It’s thus “list”: ${list} This works the same way for session.setAttribute(“name”, value) and application.setAttribute(“name”, value). The value is in EL available by just ${name}. More detail: EL uses by default PageContext#findAttribute() which scans in subsequently the page, request, session and application scopes for … Read more

Why put JSP in WEB-INF?

Files in WEB-INF are not visible to the users. It’s a bit safer that way. If (a contrived example) you are including db.jsp, but by itself it throws an exception, a malicious user can open http://yoursite.com/db.jsp and get some insight on your application (worst – the database credentials) from the exception message.

Java EE vs JSP vs JSF [closed]

Is JSP “dead” in favor of JSF? JSF has countless benefits over JSP. For instance: It defines a MVC approach It set up componentization standards It has apply values feature Built-in AJAX A defined view context control Allows for rich interfaces extensions like Primefaces And we can go on and on. You can still use … Read more

How to encode a String representing URL path with JSTL?

The <c:url> does not encode the URI as specified in its value, but just URL request parameters which are specified by a nested <c:param>. The IBM article which you linked also doesn’t tell otherwise. I think that you confused it with “URL rewriting” (which is in essence nothing more than appending the jsessionid whenever necessary). … Read more

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