java - index.jsp not working, just shows source code on browser -
in spring mvc application, i'm trying pass list jsp page , show on table, index.jsp isn't rendered , shows source code on browser.
here controller:
package com.orantaj.controllers; import com.orantaj.service.eventservice; import org.springframework.beans.factory.annotation.autowired; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.restcontroller; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; @restcontroller public class indexcontroller { @autowired eventservice eventservice; @requestmapping(value = "/") public void setevents(httpservletrequest request, httpservletresponse response) { try { request.setattribute("basketballevents", eventservice.getbasketballevents()); request.getrequestdispatcher("index.jsp").forward(request, response); } catch (exception e) { e.printstacktrace(); } } }
and here jsp:
<%@ page import="com.orantaj.model.basketballevent" %> <%@ page import="java.util.list" %> <html> <head> <title></title> </head> <body> <table>
<tr>
<th>maç kodu</th> <th>lig</th> <th>maç saati</th> <th>takımlar</th> </tr>
<%list<basketballevent> basketballevents = (list<basketballevent>) request.getattribute("basketballevents");%>
<%if (basketballevents != null && basketballevents.size() > 0) {%>
<%for (basketballevent event : basketballevents) {%>
<tr>
<td><%=event.getmatchcode()%></td> <td><%=event.getleague()%></td> <td><%=event.getmatchdate()%></td> <td><%=event.gethometeam() + " " + event.getawayteam()%></td> </tr>
<% } } %>
</table> </body> </html>
what wrong?
you may need annotate controller class @controller
instead of using @restcontroller
annotation implies request handling method assumes @responsebody
semantics, (from javadoc):
indicates method return value should bound web response body.
you can check annotation inernals:
Comments
Post a Comment