Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING error occurs when passing model attributes to the JSP page - spring

I'm passing model attributes to the view from my spring controller but the jsp page is not displayed. In the console i'm getting following error :
net::ERR_INCOMPLETE_CHUNKED_ENCODING 200
The controller :
private final String POYNT_DETAILS_VIEW = "full_poynt_view";
#RequestMapping(value = "/businessDetails/{businessId}/poynt", method = RequestMethod.GET)
public String viewBusinessDetails(Model model, #PathVariable String businessId) throws IOException {
PoyntBusinessDetails poyntBusinessDetails = poyntApiClient.getPoyntBusinessDetails(businessId,poyntCloudBaseBusinessUrl);
model.addAttribute("poyntBusinessDetails", poyntBusinessDetails);
return POYNT_DETAILS_VIEW;
}
The view :
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<div style="padding: 5px">
<span class="main-text">Business Name</span>:
<span class="sub-text">${poyntBusinessDetails.legalName}</span>
</div>
The model class :
public class PoyntBusinessDetails {
private String legalName;
// getters and setters
}

Instead of
<span class="sub-text">${poyntBusinessDetails.legalName}</span>
Use
<span class="sub-text"><c:out value="${poyntBusinessDetails.legalName}"/></span>

Related

404 error,not displaying view content in jsp java spring boot

so I have some JSP views in my Spring Boot code, one of them which I have a problem with is showInfo.jsp:
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: PC
Date: 02.05.2022
Time: 15:20
To change this template use File | Settings | File Templates.
--%>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%--#elvariable id="banner" type="java.util.List<pl.coderslab.entity.Banners>"--%>
<%--#elvariable id="rent" type="java.util.List<pl.coderslab.entity.Rents>"--%>
<c:forEach var = "banners" items="${banner}">
<table>
<tr>
<th>Street</th>
<th>Price</th>
<th>is Rented</th>
<th>rented from</th>
<th>rented until</th>
</tr>
<tr>
<td>${banners.street}</td>
<td>${banners.price}</td>
<td>${banners.is_rented}</td>
<td>${banners.rents.rented_from}</td>
<td>${banners.rents.rented_until}</td>
</tr>
<td><input type="submit" value="Wstecz"></td>
</table>
</c:forEach>
</body>
</html>
I also have dashboard.jsp:
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: PC
Date: 02.05.2022
Time: 15:20
To change this template use File | Settings | File Templates.
--%>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Dashboard</h1>
<br>
<table>
<tr>
<th>Banners</th>
<th>Localization</th>
</tr>
<%--#elvariable id="banners" type="java.util.List<pl.coderslab.entity.Banners>"--%>
<c:forEach var="banner" items="${banners}">
<tr>
<td>Banner</td>
<td>${banner.street}</td>
<td><a href="http://localhost:8080/dashboard/info/${banner.id}" >Wiecej informacji</a></td>
<td> <a href="http://localhost:8080/dashboard/edit/${banner.id}" >Edytuj </a></td>
<td> <a href="http://localhost:8080/dashboard/delete/${banner.id}" >Usun </a></td>
</tr>
</c:forEach>
</table>
</body>
</html>
The problem is when I click on one of hrefs, it redirects but I have 404 error "Not found". But I have controller to every href, for example showInfo controller:
#RequestMapping(value = "/dashboard/info/{id}", method = RequestMethod.GET)
public String showInfo(Model model, #PathVariable("id") int id){
List<Banners> banners = bannerDao.getBannerById(id);
model.addAttribute("banner", banners);
return "showInfo";
}
#RequestMapping(value = "/dashboard/info/{id}", method = RequestMethod.POST)
public String info(){
return "redirect:/dashboard";
}
I don't know what is problem here. I have #RequestMapping's, all properties and dependencies are included.

Internalization fmt

I have the page jsp :
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="f" %>
<%# page session="true" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%# page session="true" %>
<%# page trimDirectiveWhitespaces="true" %>
<%
String locale = "fr_FR";
%>
<fmt:setLocale value="${locale }"/>
<fmt:bundle basename="com.stock.led.i18n.applicationresources"></fmt:bundle>
I have two properties files on package "com.stock.led.i18n.applicationresources" applicationresources_en_US and applicationresources_fr_FR. The applicationresources_en_US file is always used and the _fr_FR is set By fmt SetLocale, i dont understand why ??
After Research i found that the responsible is the header HTTP "Accept-Language" By testing 3 Browsers , the browser installed in French works perfect and the others on english Nope.
Why <fmt:setLocale value="${locale }"/> doesn't force the language and ignore the header HTTP "Accept-Language".

Why model.addAttribute and ${} is not matching and it shows just . on web?

I just started to learn jsp and spring. I deleted formattedDate (as a default) in HomeController.java and changed to model.addAttribute("answer", "yes") and on web, it only shows . and i don't understand why.
I tried to put definition like String answer = "yes" but it didnt work.
this is HoneController.java:
#Controller
public class HomeController {
#RequestMapping("/main")
public String home(Locale locale, Model model) {
model.addAttribute("answer", "yes");
return "home";
}
}
and here is home.jsp:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page session="false" pageEncoding="UTF-8" %>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>
hello
</h1>
<P> Is it happening? : ${answer}. </P>
</body>
</html>
There was no error messages

Language Specific Custom 404 page in Liferay

I know the procedure for adding the custom 404 page. What I want is to fetch user language in 404 page and show the error message in his locale.
Sorry for Posting the question but the answer may be helpful for others. Just create a jsp and add this code there
<%# page import="com.liferay.portal.util.PortalUtil" %>
<%# page import="com.liferay.portal.NoSuchLayoutException" %>
<%# page import="com.liferay.portal.service.LayoutLocalServiceUtil" %>
<%# page import="com.liferay.portal.util.WebKeys" %>
<%# page import="com.liferay.portal.model.LayoutSet" %>
<%# page import="com.liferay.portal.model.User" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
User currentUser=null;
try {
currentUser = PortalUtil.getUser(request);
} catch (Exception e) {
e.printStackTrace();
}
%>

No mapping found for HTTP request with URI [/resources/css/styles.css] in DispatcherServlet with name 'SpringDispatcher'

I am developing simple web application using Spring MVC. Could you please point me out why the resources are not rendered on the page when I am accessing it? The whole page is being rendered however.
Here my project structure
I am receiving the following warning:
No mapping found for HTTP request with URI [/resources/css/styles.css] in DispatcherServlet with name 'SpringDispatcher'
JSP page that holds the links to the resources:
includes.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="base" value="${pageContext.request.contextPath}"/>
<link href="<c:url value="${base}/resources/css/pure/pure-min.css" />" rel="stylesheet">
<link href="<c:url value="${base}/resources/css/styles.css" />" rel="stylesheet">
<link href="<c:url value="${base}/resources/css/menu.css" />" rel="stylesheet">
<script src="${base}/resources/js/validateInput.js"></script>
JSP page that has to be rendered:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<jsp:include page="/resources/includes.jsp"/>
</head>
<body>
<div id="main-container">
<div class="site-content">
<h1 class="fueling-header">Registration</h1>
<form class="pure-form pure-form-aligned"
action="/register"
method="post"
onsubmit="return validateUserInput();">
</fieldset>
</form>
</div>
</div>
</body>
</html>
Here is my WebAppInitializer code:
public class WebAppContextInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext annotationConfigWebApplicationContext = new AnnotationConfigWebApplicationContext();
annotationConfigWebApplicationContext.register(WebContextConfiguration.class);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
"SpringDispatcher",new DispatcherServlet(annotationConfigWebApplicationContext)
);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
ContextConfiguration class
#Configuration
#EnableWebMvc
#Import(ServiceContextConfiguration.class)
#ComponentScan("controllers")
public class WebContextConfiguration {
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
#Bean(name = "view_resolver")
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
internalResourceViewResolver.setPrefix("/WEB-INF/jsp/");
internalResourceViewResolver.setSuffix(".jsp");
return internalResourceViewResolver;
}
}
And my simple controller
#Controller
public class BasicController {
#RequestMapping(value = "/greeting")
public String sayBasic(Model model){
model.addAttribute("greeting", "Hello world");
return "register";
}
}
The problem was that I had the cyclic reference in another controller i.e. the get method and post were mapped to the same logical view name. My configuration was correct.
For those who will meet the same problem: remove all request mappings and add them step by step till you will see where the problem occurred.
Remove ${base} as it is adding additional / Character.

Resources