• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

When table has no data page shows an error

 
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am creating a CRUD application in Spring MVC. So, I have a table on the page that shows all data and also I provide it with pagination.And my problem is when the table has at least one row it works and shows data properly, but if  table doesn't have any data (no row) the page shows an error.

This is my Controller for this page:

This is table body:

This is pagination part:

And here is the error which I am getting when table has no data:

There was an unexpected error (type=Internal Server Error, status=500).
'end' < 0
javax.servlet.jsp.JspTagException: 'end' < 0
at javax.servlet.jsp.jstl.core.LoopTagSupport.validateEnd(LoopTagSupport.java:487)
at org.apache.taglibs.standard.tag.rt.core.ForEachTag.setEnd(ForEachTag.java:62)
at org.apache.jsp.templates.servers_002dinfo_jsp._jspx_meth_c_005fforEach_005f1(servers_002dinfo_jsp.java:794)
at org.apache.jsp.templates.servers_002dinfo_jsp._jspService(servers_002dinfo_jsp.java:251)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
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:53)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at org.springframework.security.web.header.HeaderWriterFilter$HeaderWriterRequestDispatcher.forward(HeaderWriterFilter.java:143)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:170)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1371)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1117)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1056)
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.doGet(FrameworkServlet.java:897)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
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:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
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:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
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)

What is the problem here?
 
Master Rancher
Posts: 4208
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:forEach begin="0" end="${servers.totalPages-1}" var="i">

When totalPages is zero then this will give you the error as end will be -1.

You might need to put in a special case when there is no data.
Maybe just displaying some text saying "No servers found", with no page numbers.
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Dave, it works properly!

I added this condition:
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Small question here:

Well, in the table body I have checkboxes at beginning of each row and their value is corresponding rows id. I want that after checking some rows the user will be able to delete checked rows. I send post request to my controller,  but the values doesn't come there. What is the reason of it and how to solve it?

My controller for the page which table on:


My post method controller which tries to handle that request:


And the table here:

 
Dave Tolls
Master Rancher
Posts: 4208
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the first step with this is to hit F12 in the browse and click on the network tab of the developer tools and see exactly what is sent to the server when you submit the request.
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Well, the first step with this is to hit F12 in the browse and click on the network tab of the developer tools and see exactly what is sent to the server when you submit the request.


Nothing sended

General

Request URL: http://localhost:8080/servers-info
Request Method: GET
Status Code: 200
Remote Address: [::1]:8080
Referrer Policy: no-referrer-when-downgrade


Response Headers

Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Language: en-US
Content-Type: text/html;charset=UTF-8
Date: Wed, 21 Aug 2019 13:20:23 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block


Request Headers

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
Cookie: JSESSIONID=BB301CF09CCD8868198E1BA79804BC48
Host: localhost:8080
Referer: http://localhost:8080/servers-info
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
 
Dave Tolls
Master Rancher
Posts: 4208
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, well what is the HTML that you think is supposed to send the list of selected ids to the server?

That is, what is the HTML on the browser (forget the JSP for now).
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:OK, well what is the HTML that you think is supposed to send the list of selected ids to the server?

That is, what is the HTML on the browser (forget the JSP for now).


-The form tag which has post method and wraps the table?
 
Dave Tolls
Master Rancher
Posts: 4208
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
What does that look like on the browser?

Does it have the data?
Is the data in the correct fields?
Is it going to send to the correct URL?
etc etc
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Yes.
What does that look like on the browser?

Does it have the data?
Is the data in the correct fields?
Is it going to send to the correct URL?
etc etc



It looks like a single row on the table
No, it doesn't have
-
Yes, it is going to correct URL which I want to send to - /servers-info/delete-selected URL
 
Dave Tolls
Master Rancher
Posts: 4208
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So there's no data in the table?

Can you paste the HTML in here?
It's hard to visualise what your issue is.
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:So there's no data in the table?

Can you paste the HTML in here?
It's hard to visualise what your issue is.


There is data in the table, yes. I'm sorry, I got the question in a wrong way.
And I have shared html of the table above.
 
Dave Tolls
Master Rancher
Posts: 4208
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you've posted the JSP page that produces the table.
I was specifically asking for the HTML as it appears in the browser.

That's a very important check to ensure that your JSP is producing what you think it is producing.
You need that because it is that which defines what happens on the browser.

Essentially, when you get a situation where an event on a browser doesn't seem to produce anything you want to work from the browser, not the JSp (which is server-side).
So first step is "does it send anything".
If so, what does it send.
If that's correct then that is the point you go to the server and see what the servlet is doing with the request.

If it's not sending the correct thing (or anything at all) you then need to look at the HTML on the browser, and possibly debug Javascript if there's any processing before making a request to the server.
That HTML (and any associated script) will determine what is happening.

So, from what you posted earlier it looks like it's not making a request.
So you need to look at the actual HTML.
Until you determine what is not correct in that then there is little point peering at JSP tags.
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:No, you've posted the JSP page that produces the table.
I was specifically asking for the HTML as it appears in the browser.

That's a very important check to ensure that your JSP is producing what you think it is producing.
You need that because it is that which defines what happens on the browser.

Essentially, when you get a situation where an event on a browser doesn't seem to produce anything you want to work from the browser, not the JSp (which is server-side).
So first step is "does it send anything".
If so, what does it send.
If that's correct then that is the point you go to the server and see what the servlet is doing with the request.

If it's not sending the correct thing (or anything at all) you then need to look at the HTML on the browser, and possibly debug Javascript if there's any processing before making a request to the server.
That HTML (and any associated script) will determine what is happening.

So, from what you posted earlier it looks like it's not making a request.
So you need to look at the actual HTML.
Until you determine what is not correct in that then there is little point peering at JSP tags.


Thank you, so much, Dave. I followed what you said and I achieved what I want
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you check my code? Did I do in the right way?
This is HTML on the browser:


This is JavaScript:


And this is my controller:
 
Dave Tolls
Master Rancher
Posts: 4208
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it work?
And is it easy to read?

That's pretty much my definition of "OK".
 
Asif Haciyev
Ranch Hand
Posts: 65
1
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Does it work?
And is it easy to read?

That's pretty much my definition of "OK".


Yes, it works.
Yes.
Thank you, Dave.
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!