Whats wrong with this?

Whats wrong with this?

vsekvsek Posts: 30Questions: 17Answers: 0

Ok this is mysql database, java using eclipse springboot webapp. Everything works but the data comes back as one big unformatted blob on the jsp page when going to web site localhost:8080/index. I know I am almost there but somethings not 100% correct.I removed the jsp datatable part on the jsp and got the same result, so the page is apparently not seeing that but I dont know why?

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.service.ServiceInterface;

import model.ScraperObject;
@RestController
public class HomeRestController {
    @Autowired
    private ServiceInterface scraperService;

    @RequestMapping(path="/index", method=RequestMethod.GET)
    public List<ScraperObject> getAllNonDectivatedData(){
        List<ScraperObject>  allNonDectivated = scraperService.getAllNonDeactivatedOnes();
        return allNonDectivated;
    }
}

jsp page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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>Spring Boot + JPA + Datatables</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
    <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
    <script>$(document).ready( function () {
         var table = $('#scrapedTable').DataTable({
                "sAjaxSource": "/scrapedData",
                "order": [[ 0, "asc" ]],
                "columns": [
                      { "data": "price"},
                      { "data": "description" },
                      { "data": "url" }
                ]
         })
    });
    </script>
</head>
<body>
    <h1>Employees Table</h1>
    <table id="scrapedTable" class="display">
      
       <!-- Header Table -->
       <thead>
            <tr>
                <th>Price</th>
                <th>Description</th>
                <th>Url</th>
            </tr>
        </thead>
        <!-- Footer Table -->
        <tfoot>
            <tr>
                <th>Price</th>
                <th>Description</th>
                <th>Url</th>
            </tr>
        </tfoot>
    </table>

</body>

</html>

pojo

package model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class ScraperObject {
    
    //private long id;
    //private String name;

    
    //private boolean active;
    @Id
    @GeneratedValue
    @Column(name="url")
    private String url;
    @Column(name="description")
    private String description;
    @Column(name="price")
    private String price;
    //public String scrapedData;
//  public String date;
//  public String location;
//  public UUID guid;
//  public String picture;
//  public boolean deactivatedBoolean;

    public void setUrl(String aUrl) {
        url =aUrl;
    }
    public String getUrl() {
        return url;
    }

    
        
    public void setPrice(String aPrice) {
        price = aPrice;
    }
    public String getPrice() {
        return price;
    }
    public void setDescription(String aDescription) {
        description = aDescription;
    }
    public String getDescription() {
        return description;
    }
    
    /*
     * 
     * public String getPicture() { 
        return picture;
    }
    public void setPicture(String aPict) {
        picture = aPict;
    }
    public boolean getDeactivated() {
        return deactivatedBoolean;
    }
    public void setDeactivated(boolean aBoolean) {
        deactivatedBoolean = aBoolean;
    }
    public UUID getGuid() {
        return guid;
    }
    public String getLocation(String aLocation) {
        return location;
    }
    public String  getDate() {
        return date;
    }
    public String getLocation() { 
        return location;
    }
    public void setLocation(String aLocation) {
        location = aLocation;
    }
    public void setGuid(UUID aGuid) {
        guid = aGuid;
    }
    public void setDate(String aDate) {
        date = aDate;
    }
    public void setSrappedData(String aScrappedData) {
        scrapedData =aScrappedData;
    }
    public String getScrapedData() {
        return scrapedData;
    }
    */
}


service

package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.repository.ScraperMqSQL;

import model.ScraperObject;

@Service("scraperService")
public class ScraperServiceImpl implements ServiceInterface{
    @Autowired
    private ScraperMqSQL repository;

    @Override
    public List<ScraperObject> getAllNonDeactivatedOnes() {
        return repository.getAllNonDeactivated();
    }
}

Answers

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin

    I don't know Java I'm afraid, so I can't help in that respect. If you need a hand with the Java stuff, you'd probably be best asking on StackOverflow.

    What do you get in your browser if you load /scrapedData directly (with the domain name, whatever that might be of course)? Also, can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Thanks,
    Allan

This discussion has been closed.