I am facing this strange behaviour whith Spring MVC and JSP where the ModelAttribute is sent to the JSP with populated fields but when it is returned to the controller all the fields are null.
So first of all I put an object as attribute in the model.
#PostMapping("qcm")
public String qcm(#ModelAttribute("qcm") Qcm formQcm, Model model) {
Qcm q = props.getQcm(formQcm.getDomaine(), formQcm.getMode());
model.addAttribute("qcm", q);
this.qcm = q;
return "qcm";
}
The ModelAttribute here works just fine. But note that I add a new attribute to the model here.
In the qcm.jsp page I display a form with some information from the qcm object I put in the model earlier. That means there is no way I send the fields of qcm as null in the first place.
Here is qcm.jsp:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<div class="container">
<h1 class="h3 mb-3 font-weight-normal">QCM</h1>
<form:form action="sendqcm" modelAttribute="qcm" method="POST">
<c:forEach var="question" items="${qcm.questions}">
<p>${question.data}?</p>
<c:forEach var="reponse" items="${question.reponses}">
<div class="form-check form-check-inline">
<form:radiobutton path="${question.chosenReponse}" value="${reponse}" label="${reponse.data}" class="form-check-input"/>
</div>
</c:forEach>
</c:forEach>
<input type="submit" value="envoyer" class="save" class="btn btn-lg btn-primary btn-block"/>
</form:form>
</div>
</body>
</html>
The informations are displayed just fine. I mapped the action to the sendqcm controller. Here it is:
#PostMapping("sendqcm")
public String sendqcm(#ModelAttribute("qcm") Qcm formQcm, Model model) {
System.out.println("Domaine -> " + formQcm.getDomaine());
System.out.println("Mode -> " + formQcm.getMode());
for(Question q : formQcm.getQuestions()) {
System.out.println(q.getChosenReponse());
}
for (Question q : formQcm.getQuestions()) {
if (q.answeredCorrectly())
score++;
}
model.addAttribute("score", score);
return "reponses";
}
The two lines of System.out.println() return null and then the program fails with NullPointerException:
java.lang.NullPointerException
at fr.insa.controller.AppController.sendqcm(AppController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
You can add the #ControllerAdvice assists a controller and in particular, so #ModelAttribute methods that apply to all #RequestMapping methods.
Related
I'm using thymeleaf 3.0.7 nad Spring security and trying to make a webapp. Logging and creating accounts runs well but before logging (viewing page as anonymous) i'm getting errors as below:
2018-07-24 21:09:19.124 [http-bio-8090-exec-7] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-bio-8090-exec-7] Exception processing template "error/general": An error happened during template parsing (template: "ServletContext resource [/WEB-INF/views/error/general.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "ServletContext resource [/WEB-INF/views/error/general.html]")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:355)
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:188)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:467)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:338)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "#authorization.expression('isAuthenticated()')" (template: "fragments/layout" - line 34, col 21)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
... 34 common frames omitted
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#authorization.expression('isAuthenticated()')" (template: "fragments/layout" - line 34, col 21)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:290)
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:165)
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138)
at org.thymeleaf.standard.expression.NegationExpression.executeNegation(NegationExpression.java:149)
at org.thymeleaf.standard.expression.ComplexExpression.executeComplex(ComplexExpression.java:86)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:112)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:125)
at org.thymeleaf.standard.processor.StandardIfTagProcessor.isVisible(StandardIfTagProcessor.java:59)
at org.thymeleaf.standard.processor.AbstractStandardConditionalVisibilityTagProcessor.doProcess(AbstractStandardConditionalVisibilityTagProcessor.java:61)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95)
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314)
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205)
at org.thymeleaf.engine.Model.process(Model.java:282)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1587)
at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleOpenElementEnd(TemplateHandlerAdapterMarkupHandler.java:304)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:278)
at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleOpenElementEnd(OutputExpressionInlinePreProcessorHandler.java:186)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:124)
at org.attoparser.HtmlElement.handleOpenElementEnd(HtmlElement.java:109)
at org.attoparser.HtmlMarkupHandler.handleOpenElementEnd(HtmlMarkupHandler.java:297)
at org.attoparser.MarkupEventProcessorHandler.handleOpenElementEnd(MarkupEventProcessorHandler.java:402)
at org.attoparser.ParsingElementMarkupUtil.parseOpenElement(ParsingElementMarkupUtil.java:159)
at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:710)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301)
... 36 common frames omitted
Caused by: java.lang.IllegalArgumentException: Authentication object cannot be null
at org.springframework.security.access.expression.SecurityExpressionRoot.<init>(SecurityExpressionRoot.java:61)
at org.springframework.security.web.access.expression.WebSecurityExpressionRoot.<init>(WebSecurityExpressionRoot.java:36)
at org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler.createSecurityExpressionRoot(DefaultWebSecurityExpressionHandler.java:43)
at org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler.createSecurityExpressionRoot(DefaultWebSecurityExpressionHandler.java:33)
at org.springframework.security.access.expression.AbstractSecurityExpressionHandler.createEvaluationContext(AbstractSecurityExpressionHandler.java:66)
at org.thymeleaf.extras.springsecurity4.auth.AuthUtils.authorizeUsingAccessExpression(AuthUtils.java:194)
at org.thymeleaf.extras.springsecurity4.auth.Authorization.expression(Authorization.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:120)
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:106)
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:52)
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:359)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:89)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:110)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:334)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263)
... 64 common frames omitted
Since it mentions /WEB-INF/views/error/general.html here it is:
<!DOCTYPE html>
<html xmlns:th="www.thymeleaf.org">
<head>
<title>Error page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="#{/resources/css/bootstrap.min.css}"/>
<link href="../../../resources/css/core.css" rel="stylesheet" media="screen" th:href="#{/resources/css/core.css}"/>
</head>
<body>
<div class="container">
<div th:replace="fragments/layout :: header"></div>
<div th:replace="fragments/components :: alert (type='danger', message=${errorMessage})">Error: Error</div>
<div th:replace="fragments/layout :: footer"></div>
</div>
</body>
</html>
And layout.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml">
<head>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="#{/resources/css/bootstrap.min.css}"/>
</head>
<body>
<!-- Header -->
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#" th:href="#{/}">Demo project</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li th:classappend="${module == 'about' ? 'active' : ''}">
About
</li>
<li th:classappend="${module == 'calendar' ? 'active' : ''}">
Calendar
</li>
<li th:classappend="${module == 'event' ? 'active' : ''}"
sec:authorize="hasRole('ROLE_ADMIN')"
>
Formularz
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li th:if="not ${#authorization.expression('isAuthenticated()')}">
<a href="/signin" th:href="#{/signin}">
<span class="glyphicon glyphicon-log-in" aria-hidden="true"></span> Sign in
</a>
</li>
<li th:if="${#authorization.expression('isAuthenticated()')}">
<a href="/logout" th:href="#{#}" onclick="$('#form').submit();">
<span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> Logout
</a>
<form style="visibility: hidden" id="form" method="post" action="#" th:action="#{/logout}"></form>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
<!-- Footer -->
<div th:fragment="footer" th:align="center">
© <span th:text="${#temporals.format(#temporals.createNow(), 'yyyy')}">2017</span>
Demo project <span th:text="${#environment.getProperty('app.version')}"></span>
</div>
</body>
</html>
It says that line
<li th:if="not ${#authorization.expression('isAuthenticated()')}">
is the problem and in fact when i change it to return false no errors are thrown. When i change it to use !isAuthenticated() or isAnonymous() instead of "not [...] isAuthenticated()" it throws errors. I have thymeleaf-extras-springsecurity4 dependency added in my pom.xml file as well.
My bet is that i have to work on the fact the authenticated object is null. But what else it could be when i'm checking the website as anonymous?
In general you should always have an authentication object on every page of secured application. Filter org.springframework.security.web.authentication.AnonymousAuthenticationFilter is responsible for setting AnonymousAuthenticationToken in the current security context when it (token) is missing. If this filter is not called it may indicate some problems in security configuration.
BTW try to use xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4" namespace in your Thymeleaf templates. It will shorten security checks a little bit: <div sec:authorize="isAuthenticated()">.
Good day!
When i deploy war to tomcat it drop to me this exception:
May be someone can help solve that problem with #Transactional annotation, cannot solve that problem in above 2 weeks :(
n22-Feb-2018 14:52:54.125 SEVERE [http-nio-8080-exec-11] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [/page] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.mycompany.app.controller.TypeController.listAll(TypeController.java:24)
at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
web.xml
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
mvc-dispatcher-servlet.xml
<context:component-scan base-package="com.mycompany.app" />
<context:component-scan base-package="com.mycompany.app.controller" />
<context:component-scan base-package="com.mycompany.app.service" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
TypeController.java
#Controller
public class TypeController {
private TypeServiceImpl typeService;
#RequestMapping(value = "/main")
public String listAll(Map<String, Object> map) {
map.put("type", new Type());
map.put("typeList", typeService.listAll());
return "index";
}
#RequestMapping("/")
public String home() {
return "redirect:/main";
}
#RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(#ModelAttribute("type") Type type, BindingResult bindingResult) {
typeService.add(type);
return "redirect:/main";
}
#RequestMapping(value = "/delete/{id}")
public String deleteType(#PathVariable("id") Integer id) {
typeService.delete(id);
return "redirect:/main";
}
}
TypeServiceImpl.java
Dont using DAO
#Service
public class TypeServiceImpl implements TypeService {
private SessionFactory sessionFactory;
#Override
#Transactional
public void add(Type type) {
sessionFactory.getCurrentSession().save(type);
}
#Override
#Transactional
#SuppressWarnings("unchecked")
public List<Type> listAll() {
return sessionFactory.getCurrentSession().createQuery("from Type").list();
}
#Override
#Transactional
public void delete(Integer id) {
Type type = sessionFactory.getCurrentSession().load(Type.class, id);
if (type != null) {
sessionFactory.getCurrentSession().delete(type);
}
}
}
Type.java
#Entity
#Table(name = "type")
public class Type {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "id_type")
private Integer id_type;
#Column(name = "type_name")
private String type_name;
// Communication with Event
#OneToMany(fetch = FetchType.LAZY, mappedBy = "type")
private List<Event> event;
public Type() {
}
public Type(Integer id_type, String type_name) {
this.id_type = id_type;
this.type_name = type_name;
}
//Default getters and setters
}
index.jsp
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# page contentType="text/html;charset=UTF-8" language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello World Page</title>
</head>
<body>
<form:form method="post" action="add" modelAttribute="type">
<table>
<tr>
<td><form:label path=id_type>Type's ID</form:label></td>
<td><form:input path="id_type" /></td>
</tr>
<tr>
<td><form:label path=type_name>Type name</form:label></td>
<td><form:input path="type_name" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
<h3>Types</h3>
<c:if test="${!empty typeList}">
<table class="data">
<tr>
<th>Type ID</th>
<th>Type Name</th>
<th> </th>
</tr>
<c:forEach items="${typeList}" var="type">
<tr>
<td>${type.id_type}}</td>
<td>${type.type_name}</td>
<td>Delete</td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
Thanks for watching!!!
I think you might be missing an #Autowired annotation for your service.
#Autowired
private TypeService typeService;
At the moment i can't see where your instantiating the service class.
i use spring data neo4j to work,i have a repository to recommend movie,i think cypher have not problem,and i can get the recommendation,but i can not get the value of Movie.title and rating ,why it shows movie id not property to the recommendation.class,in my log and error info you can see,why ?
i have severl similar problems,it seems cant get the value in jsp?help me thank you very much .heart man
recommendation.class
package com.oberon.fm.domain;
import org.springframework.data.neo4j.annotation.QueryResult;
#QueryResult
public class MovieRecommendation {
Movie movie;
int rating;
the repository
#Query("match (user:User {login: {0}})-[r:RATED]->(movie)<-[r2:RATED]-(other)-[r3:RATED]->(otherMovie) "
+ " where r.stars >= 3 and r2.stars >= r.stars and r3.stars >= r.stars "
+ " with otherMovie, avg(r3.stars) as rating, count(*) as cnt"
+ " order by rating desc, cnt desc"
+ " return otherMovie limit 10")
List<MovieRecommendation> getRecommendations(String login);
my controller
#RequestMapping(value = "/user", method = RequestMethod.GET)
public String profile(Model model, HttpServletRequest request) {
// User user=populator.getUserFromSession();
HttpSession session = request.getSession(false);
User user = (User) session.getAttribute("user");
model.addAttribute("user", user);
if (user != null) {
List<MovieRecommendation> mr = movieRepository.getRecommendations(user.getLogin());
model.addAttribute("recommendations", mr);
}
return "user/index";
}
index.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%--#elvariable id="user" type="com.oberon.fm.domain.User"--%>
<%--#elvariable id="recommendations"type="java.util.List<com.oberon.fm.domain.MovieRecommendation>"--%>
<%--#elvariable id="recommendation"type="com.oberon.fm.domain.MovieRecommendation"--%>
<html>
<head>
<title>Profile</title>
<link rel="stylesheet" type="text/css" href="/Web/css/style.css"/>
</head>
<body>
<div class="span-third">
<h2>Your recommendations</h2>
</div>
<div class="span-third last">
<h2>${fn:length(recommendations)}</h2>
</div>
<ul class="rated-movies-list span-all last">
<c:choose>
<c:when test="${not empty recommendations}">
<c:forEach items="${recommendations}" var="recommendation">
<c:set var="movie" value="${recommendation.movie}"/>
<c:set var="stars" value="${recommendation.rating}"/>
<li>
<h4> <a href="<c:url value="/movies/${movie.id}" />"><c:out value="${movie.title}"/>
(${movie.year}) - "${movie.tagline}"</a>
<img class="rating" alt="${stars} stars" src="<c:url value="/images/rated_${stars}.png" />"/>
</h4>
</li>
</c:forEach>
</c:when>
<c:otherwise>
There are no recommendations for you, perhaps you have to add some friends?
</c:otherwise>
</c:choose>
</ul>
<div class="break"></div>
</div>
</div>
i can get the length of recommendation
log and error info
16:19:32.403 [http-nio-8080-exec-8] DEBUG o.s.w.b.a.s.HandlerMethodInvoker - Invoking request handler method: publicjava.lang.String com.oberon.fm.controller.UserController.profile(org.springframework.ui.Model, javax.servlet.http.HttpServletRequest)
16:19:32.403 [http-nio-8080-exec-8] DEBUG o.s.t.jta.JtaTransactionManager - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
16:19:32.404 [http-nio-8080-exec-8] DEBUG o.s.d.n.s.q.CypherQueryEngineImpl - Executing cypher query: match (user:User {login: {0}})-[r:RATED]->(movie)<-[r2:RATED]-(other)-[r3:RATED]->(otherMovie) where r.stars >= 3 and r2.stars >= r.stars and r3.stars >= r.stars with otherMovie, avg(r3.stars) as rating, count(*) as cnt order by rating desc, cnt desc return otherMovie limit 10 params {0=micha}
16:19:32.739 [http-nio-8080-exec-8] DEBUG o.s.t.jta.JtaTransactionManager - Initiating transaction commit
16:19:32.740 [http-nio-8080-exec-8] DEBUG c.o.fm.controller.UserController - ()()()()()()()()()()()[com.oberon.fm.domain.MovieRecommendation#bc5162, com.oberon.fm.domain.MovieRecommendation#1b8ceab]
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'user/index'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'user/index'; URL [/pages/user/index.jsp]] in DispatcherServlet with name 'context'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Added model object 'user' of type [com.oberon.fm.domain.User] to request in view with name 'user/index'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Added model object 'recommendations' of type [java.util.ArrayList] to request in view with name 'user/index'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Added model object 'org.springframework.validation.BindingResult.user' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'user/index'
16:19:32.740 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource [/pages/user/index.jsp] in InternalResourceView 'user/index'
16:19:33.838 [http-nio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - Error rendering view [org.springframework.web.servlet.view.JstlView: name 'user/index'; URL [/pages/user/index.jsp]] in DispatcherServlet with name 'context'
org.apache.jasper.JasperException: An exception occurred processing JSP page /pages/user/index.jsp at line 86
83: <c:choose>
84: <c:when test="${not empty recommendations}">
85: <c:forEach items="${recommendations}" var="recommendation">
86: <c:set var="movie" value="${recommendation.movie}"/>
87: <c:set var="stars" value="${recommendation.rating}"/>
88: <li>
89: <h4> <a href="<c:url value="/movies/${movie.id}" />"><c:out value="${movie.title}"/>:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) ~[jasper.jar:8.0.15]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470) ~[jasper.jar:8.0.15]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) ~[jasper.jar:8.0.15]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) ~[jasper.jar:8.0.15]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721) ~[catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466) ~[catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391) ~[catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318) ~[catalina.jar:8.0.15]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168) ~[spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.15]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.15]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.15]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.15]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537) [catalina.jar:8.0.15]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085) [tomcat-coyote.jar:8.0.15]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658) [tomcat-coyote.jar:8.0.15]
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) [tomcat-coyote.jar:8.0.15]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556) [tomcat-coyote.jar:8.0.15]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513) [tomcat-coyote.jar:8.0.15]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_05]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.15]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_05]
Caused by: org.apache.jasper.el.JspPropertyNotFoundException: /pages/user/index.jsp(86,26) '${recommendation.movie}' Property 'movie' not found on type com.oberon.fm.domain.MovieRecommendation
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:120) ~[jasper.jar:8.0.15]
at org.apache.jsp.pages.user.index_jsp._jspx_meth_c_005fset_005f3(index_jsp.java:879) ~[na:na]
at org.apache.jsp.pages.user.index_jsp._jspx_meth_c_005fforEach_005f2(index_jsp.java:818) ~[na:na]
at org.apache.jsp.pages.user.index_jsp._jspx_meth_c_005fwhen_005f2(index_jsp.java:782) ~[na:na]
at org.apache.jsp.pages.user.index_jsp._jspx_meth_c_005fchoose_005f2(index_jsp.java:746) ~[na:na]
at org.apache.jsp.pages.user.index_jsp._jspService(index_jsp.java:171) ~[na:na]
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) ~[jasper.jar:8.0.15]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:na]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) ~[jasper.jar:8.0.15]
... 49 common frames omitted
You need to have getters for jsp el expressions, it won't recognize public properties.
Change your MovieRecommendation class (and possibly others) to something like this:
#QueryResult
public class MovieRecommendation {
Movie movie;
int rating;
Movie getMovie() { .... }
int getRating() {....}
I am using Spring Boot with web mvc tiles. Also using Bootsrap CSS for front end
I have a main layout page named basic.jsp as
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<title><tiles:getAsString name="title" /></title>
</head>
<body>
<!-- Header -->
<tiles:insertAttribute name="header" />
<!-- Body -->
<tiles:insertAttribute name="body" />
<!-- Footer -->
<tiles:insertAttribute name="footer" />
</body>
</html>
and the tiles.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<!-- Templates -->
<definition name="layout.basic" template="/pages/layout/basic.jsp">
<put-attribute name="header" value="/pages/jsps/header.jsp" />
<put-attribute name="leftmenu" value="/pages/jsps/lmenu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/pages/jsps/footer.jsp" />
</definition>
<!-- Pages -->
<definition name="home" extends="layout.basic">
<put-attribute name="body" value="/WEB-INF/tiles/view/home/home.jsp" />
</definition>
<definition name="greet" extends="layout.basic">
<put-attribute name="body" value="/WEB-INF/tiles/view/home/register.jsp" />
</definition>
</tiles-definitions>
I want to include the spring form taglib in my register.jsp
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<div>
<div class="col-md-9 personal-info">
<form:form method="POST" id="frm" class="form-horizontal" role="form" commandName="box" action="Register">
<div class="form-group">
<label class="col-lg-3 control-label">Box Id:</label>
<div class="col-lg-8">
<form:input class="form-control" path="strBoxId" type="text" placeholder="Box Id"></form:input>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Box Name:</label>
<div class="col-lg-8">
<form:input class="form-control" type="text" path="strBoxName" value="" placeholder="Box Name"></form:input>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Address:</label>
<div class="col-lg-8">
<form:textarea class="form-control" placeholder="Address" path="strAddress"></form:textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input type="submit" class="btn btn-primary" id="register" value="Register" onclick="callMe()">
<span></span>
<input type="reset" class="btn btn-default" value="Cancel">
</div>
</div>
</form:form>
</div>
</div>
When I am running the application without including the taglib it is displaying the form, but when I am including the taglib in register.jsp, It is throwing error in cosole as well as Whitelabel Error Page in browser. Th error displayed is
2015-03-05 15:23:45.296 ERROR 8056 --- [nio-8080-exec-8] o.a.c.c.C.[. [localhost].[/].[jsp] : Servlet.service() for servlet jsp threw exception
java.util.NoSuchElementException: null
at java.util.ArrayList$Itr.next(Unknown Source)
at org.apache.jasper.compiler.Validator$ValidateVisitor.getJspAttribute(Validator.java:1385)
at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1262)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:876)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2429)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:895)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2429)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2435)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1841)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:688)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:682)
at org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:123)
at org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
at org.apache.tiles.request.render.ChainedDelegateRenderer.render(ChainedDelegateRenderer.java:68)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:188)
at org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:132)
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299)
at org.apache.jsp.pages.layout.basic_jsp._jspx_meth_tiles_005finsertAttribute_005f2(basic_jsp.java:198)
at org.apache.jsp.pages.layout.basic_jsp._jspService(basic_jsp.java:112)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
at org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265)
at org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:228)
at org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221)
at org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59)
at org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:114)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:8 37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1720)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
I don't know where it went wrong. Kindly help :(
Oh God!!! I wasted 3 hours in finding the solution. Thanks to the reply from 'guido' Spring boot taglibs
I just changed my spring boot version to 1.2.2.RELEASE and it worked !!!
I am only entering the code which is giving me error
My controller class has the following method
#RequestMapping(method=RequestMethod.GET, value="/displayUser")
public String displayUsers(Model model)
{
model.addAttribute("Users", userDetailsService.listUsers());
return "displayUser";
}
My Service class has the following method
public List<UserDetails> listUsers()
{
Query que=hibernateSessionFactory.openSession().createQuery("select userName from UserDetails");
List<UserDetails> listOfUsers=null;
try {
listOfUsers= que.list();
} catch (Exception e) {
System.err.println("Error");
}
return listOfUsers;
}
I want to list all the usernames on my JSP, so I used JSTL
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%# page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Display User</title>
</head>
<body>
<c:forEach var="Users" items="${Users}">
${Users.userName}
</c:forEach>
</body>
</html>
I am getting the following error for the above code.
javax.el.PropertyNotFoundException: Property 'userName' not found on type java.lang.String
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
javax.el.BeanELResolver.property(BeanELResolver.java:325)
javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
org.apache.el.parser.AstValue.getValue(AstValue.java:183)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
org.apache.jsp.WEB_002dINF.views.displayUser_jsp._jspx_meth_c_005fforEach_005f0(displayUser_jsp.java:119)
org.apache.jsp.WEB_002dINF.views.displayUser_jsp._jspService(displayUser_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)