Help with Crud in Java

1

I'm doing a web application in java, and I get the following error:

org.apache.jasper.JasperException: /Comics.jsp(75,16) PWC6236: According to TLD or attribute directive in tag file, attribute items does not accept any expressions

I leave the codes.

Class (Comics.java)

    package com.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table
@NamedQueries(@NamedQuery(name = "Comics.getAll", query = "SELECT e FROM Comics e"))
public class Comics implements Serializable{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column
    private int IDcomic;
    @Column
    private String nombre;
    @Column
    private int ISBN;
    @Column
    private int cantPag;
    @Column
    private int año;
    @Column
    private String autor;
    @Column
    private String categoria;
    @Column
    private String editorial;
    @Column
    private int precio;

    public int getIDcomic() {
        return IDcomic;
    }

    public void setIDcomic(int IDcomic) {
        this.IDcomic = IDcomic;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public int getISBN() {
        return ISBN;
    }

    public void setISBN(int ISBN) {
        this.ISBN = ISBN;
    }

    public int getCantPag() {
        return cantPag;
    }

    public void setCantPag(int cantPag) {
        this.cantPag = cantPag;
    }

    public int getAño() {
        return año;
    }

    public void setAño(int año) {
        this.año = año;
    }

    public String getAutor() {
        return autor;
    }

    public void setAutor(String autor) {
        this.autor = autor;
    }

    public String getCategoria() {
        return categoria;
    }

    public void setCategoria(String categoria) {
        this.categoria = categoria;
    }

    public String getEditorial() {
        return editorial;
    }

    public void setEditorial(String editorial) {
        this.editorial = editorial;
    }

    public int getPrecio() {
        return precio;
    }

    public void setPrecio(int precio) {
        this.precio = precio;
    }

    public Comics(String nombre, int ISBN, int cantPag, int año, String autor, String categoria, String editorial, int precio) {
        this.nombre = nombre;
        this.ISBN = ISBN;
        this.cantPag = cantPag;
        this.año = año;
        this.autor = autor;
        this.categoria = categoria;
        this.editorial = editorial;
        this.precio = precio;
    }

    public Comics(){}


}

DAO Class (ComicsDao.java)

package com.dao;

    import com.model.Comics;
    import java.util.List;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;


    @Stateless
    public class ComicsDao implements ComicsDaoLocal {
    @PersistenceContext
    private EntityManager em;

    @Override
        public void addComics(Comics comics) {
            em.persist(comics);
        }

    @Override
        public void editComics(Comics comics) {
            em.merge(comics);
        }

    @Override
        public void deleteComics(int IDcomic) {
            em.remove(getComics(IDcomic));
        }

    @Override
        public Comics getComics(int IDcomic) {
            return em.find(Comics.class, IDcomic);
        }

    @Override
        public List<Comics> getAllComics() {
            return em.createNamedQuery("Comics.getAll").getResultList();
        }







    }

ComicsDaoLocal.java

package com.dao;

import com.model.Comics;
import java.util.List;
import javax.ejb.Local;


@Local
public interface ComicsDaoLocal {

    void addComics(Comics comics);

    void editComics(Comics comics);

    void deleteComics(int IDcomic);

    Comics getComics(int IDcomic);

    List<Comics> getAllComics();

}

ComicsServlet.java

package com.controller;

import com.dao.ComicsDaoLocal;
import com.model.Comics;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ComicsServlet extends HttpServlet {
@EJB
private ComicsDaoLocal comicsDao;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String action=request.getParameter("action");
        String idComicsC=request.getParameter("IDcomic");
        int comicID=0;
        if(idComicsC!=null && !idComicsC.equals(""))
        comicID=Integer.parseInt(idComicsC);
        String nomb=request.getParameter("nombre");
        String ISBNN=request.getParameter("ISBN");
        int isbn=0;
        if(ISBNN!=null && !ISBNN.equals(""))
        isbn=Integer.parseInt(ISBNN);
        String cantidadPagina=request.getParameter("cantPag");
        int cant=0;
        if(cantidadPagina!=null && !cantidadPagina.equals(""))
        cant=Integer.parseInt(cantidadPagina);
        String añoo=request.getParameter("año");
        int año=0;
        if(añoo!=null && !añoo.equals(añoo))
        año=Integer.parseInt(añoo);
        String autoor = request.getParameter("autor");
        String categoriaa=request.getParameter("categoria");
        String editoriaal=request.getParameter("editorial");
        String precioo=request.getParameter("precio");
        int precio=0;
        if(precioo!=null && precioo.equals(""))
        precio=Integer.parseInt(precioo);

        Comics comics=new Comics(nomb, isbn, cant, año, autoor, categoriaa, editoriaal, precio);

        if("Add".equalsIgnoreCase(action)){
            comicsDao.addComics(comics);
        }else if("Edit".equalsIgnoreCase(action)){
            comicsDao.editComics(comics);
        }else if("Delete".equalsIgnoreCase(action)){
            comicsDao.deleteComics(comicID);
        }else if("Search".equalsIgnoreCase(action)){
            comics = comicsDao.getComics(comicID);
        }
        request.setAttribute("comics", comics);
        request.setAttribute("allComics", comicsDao.getAllComics());
        request.getRequestDispatcher("Comics.jsp").forward(request, response);
    }

Comics.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Ingreso de Comics</title>
    </head>
    <body>
        <h1>Comics</h1>
        <form action="ComicsServlet" method="POST">
        <table>
            <tr>
                <td>ID: </td>
                <td><input type="text" name="IDcomic" value="${comics.IDcomic}"></td>
            </tr>
            <tr>
                <td>Nombre: </td>
                <td><input type="text" name="nombre" value="${comics.nombre}"></td>
            </tr>
            <tr>
                <td>ISBN: </td>
                <td><input type="text" name="ISBN" value="${comics.ISBN}"></td>
            </tr>
            <tr>
                <td>Cantidad de Paginas: </td>
                <td><input type="text" name="cantPag" value="${comics.cantPag}"></td>
            </tr>
            <tr>
                <td>Año de Publicacion: </td>
                <td><input type="text" name="año" value="${comics.año}"></td>
            </tr>
            <tr>
                <td>Autor: </td>
                <td><input type="text" name="autor" value="${comics.autor}"></td>
            </tr>
            <tr>
                <td>Categoria: </td>
                <td><input type="text" name="categoria" value="${comics.categoria}">
            </tr>
            <tr>
                <td>Editorial: </td>
                <td><input type="text" name="editorial" value="${comics.editorial}"></td>
            </tr>
            <tr>
                <td>Precio: </td>
                <td><input type="text" name="precio" value="${comics.precio}"></td>
            </tr>
            <tr>
                <td colspan="2"></td>
            <input type="submit" name="action" value="Add">
            <input type="submit" name="action" value="Edit">
            <input type="submit" name="action" value="Delete">
            <input type="submit" name="action" value="Search">
            </tr>
        </table>
      </form>      
            <br>
            <table border="1">
               <th>ID</th>
               <th>Nombre</th>
               <th>ISBN</th>
               <th>Cantidad de Paginas</th>
               <th>Año</th>
               <th>Autor</th>
               <th>Categoria</th>
               <th>Editorial</th>
               <th>Precio</th>
                <c:forEach items="${allComics}" var="comi">
                    <tr>
                        <td>${comi.IDcomic}</td>
                        <td>${comi.nombre}</td>
                        <td>${comi.ISBN}</td>
                        <td>${comi.cantPag}</td>
                        <td>${comi.año}</td>
                        <td>${comi.autor}</td>
                        <td>${comi.categoria}</td>
                        <td>${comi.editorial}</td>
                        <td>${comi.precio}</td>
                    </tr>
                </c:forEach>
            </table>
    </body>
</html>

index.html

<html>
    <head>
        <title>Ventas</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <h1>Ventas de Comics</h1>
        <a href="Comics.jsp">Comics</a>
    </body>
</html>

The error tells me that the $ {allComics} has a flaw (which is the message left at the beginning of the post), it is located in Comics.jsp

    
asked by nicolasyo1WWE 13.07.2018 в 02:39
source

1 answer

0

I am not sure of the syntax ${allComics} is for a JSP in any case it is better to do a scriplet and get the attribute that you set in the servlet something like:

<% 
    Comics comics = (Comics) request.getAttribute("comics");
    List<Comics> listaComics = (List<Comics>) request.getAttribute("allComics");
%>

Then you could already put the value something like this:

<tr>
            <td>Categoria: </td>
            <td><input type="text" name="categoria" value="<%= comics.categoria %>">
</tr>

Finally, go through the list something like this:

<% for (Comics comic : listaComics) { %>
<tr>
   <td><%= comic.nombre %></td>
   <td><%= comic.año %></td>
   <td><%= comic.autor %></td>
   ......
</tr>
<% } %>
    
answered by 19.07.2018 в 18:56