how to get the base url from jsp request object?

So, you want the base URL? You can get it in a servlet as follows: String url = request.getRequestURL().toString(); String baseURL = url.substring(0, url.length() – request.getRequestURI().length()) + request.getContextPath() + “/”; // … Or in a JSP, as <base>, with little help of JSTL: <%@taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %> <%@taglib prefix=”fn” uri=”http://java.sun.com/jsp/jstl/functions” %> <c:set var=”req” value=”${pageContext.request}” /> … Read more

Passing model attribute during redirect in spring MVC and avoiding the same in URL

RedirectAttributes only work with RedirectView, please follow the same @RequestMapping(value=”/Login”,method = RequestMethod.POST) public RedirectView loginValidate(HttpServletRequest req, RedirectAttributes redir){ … redirectView= new RedirectView(“/foo”,true); redir.addFlashAttribute(“USERNAME”,uname); return redirectView; } Those flash attributes are passed via the session (and are destroyed immediately after being used – see Spring Reference Manual for details). This has two interests : they are … Read more

javax.el.PropertyNotFoundException: Property ‘foo’ not found on type com.example.Bean

javax.el.PropertyNotFoundException: Property ‘foo’ not found on type com.example.Bean This literally means that the mentioned class com.example.Bean doesn’t have a public (non-static!) getter method for the mentioned property foo. Note that the field itself is irrelevant here! The public getter method name must start with get, followed by the property name which is capitalized at only … Read more

Multiple submit buttons in the same form calling different Servlets

There are several ways to achieve this. Probably the easiest would be to use JavaScript to change the form’s action. <input type=”submit” value=”SecondServlet” onclick=”form.action=’SecondServlet’;”> But this of course won’t work when the enduser has JS disabled (mobile browsers, screenreaders, etc). Another way is to put the second button in a different form, which may or … Read more

Can HTML contain two HEAD tags

The short answer is YES. It’s not a good solution but it will absolutely work. People usually answer these questions in theory, like “no, because it’s not valid by the standards”. That’s right, it’s not. Future browsers might not support it, some source parsers may get confused, HR/IT experts checking out your portfolio may think … Read more

Java EE 6: JSF vs Servlet + JSP. Should I bother learning JSF?

JSF basically enables you to develop a web application with only model objects (JavaBeans) and views (JSP/XHTML pages). With “plain vanilla” JSP/Servlet you’ll have to bring in a lot of code to control, preprocess, postprocess, gather data, validate, convert, listen, etc the HTTP request and response. And then I’m not talking about refactoring it to … Read more

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