Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


index jsp not working just shows source code on browser


index jsp not working just shows source code on browser  using -'java,spring,jsp,model-view-controller'

In a Spring MVC application, I'm trying to pass a list to a JSP page and show it on a table, but my index.jsp isn't rendered well and just shows source code on browser.

Here is my 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 is 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 could be wrong?
    

asked Oct 13, 2015 by vijaygupta1980
0 votes
13 views



Related Hot Questions



Government Jobs Opening


...