Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

108
Vistas
How to pass parameter from jsp to controller spring mvc

I have a problem passing a parameter (data:image/png;base64 generated from a chart) from jsp (because I generated that dataurl with javascript) to spring controller.

My controller is this:

@ResponseBody
    @RequestMapping(value = "/generateChartImg", method = RequestMethod.GET,produces = "image/jpeg")
    public byte[] generateChartImg(@RequestParam("img") String img){
        final String methodName = "generateChartImg()";
        img = img.replace("data:image/png;base64,", "");
        logger.info("{} - url immagine chart: {}", methodName,img);
        byte[] decodeBase64 = Base64.getDecoder().decode(img.getBytes(StandardCharsets.UTF_8));
        return decodeBase64;
    }

and the jsp is:

    <body>
        <div id="chart" style="width:400px;height:300px;"></div>
        <input type="hidden" id="img" name="img" value="" />
    </body>

and javascript script is:

    <
script type = "text/javascript" >
    var options = {
        series: [44, 55, 13, 43, 22],
        chart: {
            width: 380,
            type: 'pie',
        },
        labels: ['Team A', 'Team B', 'Team C', 'Team D', 'Team E'],
        responsive: [{
            breakpoint: 480,
            options: {
                chart: {
                    width: 200
                },
                legend: {
                    position: 'bottom'
                }
            }
        }]
    };

var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render().then(() => {
    window.setTimeout(function() {
        chart.dataURI().then((uri) => {
            document.getElementById('img').value = uri;
        })
    }, 1000)
})

I hope someone can help me to figure it out because I just need to get an image generated by apexchart and send to controller so when I call the controller url it shows to me the image. I did a test passing a static dataurl and it works but I want now to generate dataurl and passing it from jsp. THANKS

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.