Announcement Announcement Module
Collapse
No announcement yet.
How can I show this information? (Struts + JSP) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I show this information? (Struts + JSP)

    Hi all!

    Finally I could fix the problems that I had with my web application. There was a library problem!!

    Now I'm working about how get more information of my tables, I mean... I have a table called "Alumnos" and I would like to do a search by names, by surnames, etc... basically, I want to do search by string and not by ID.

    I have implemented this function in my AlumnoDao (Interface) and AlumnoDaoHibernate and it works great because I have been debugging my application and I see that I get the values from the table but the problem is the following... how can I show this information on a web page?

    I have done a JSP file where I request all the information wich I want to search (name, surname, etc..). Later I do an accion that is related with this JSP file... (in this moment the functions that I have programmed before are working okay and they give me de information) but later I don't know how can I show the information of the database in another JSP file...


    This is my JSP file where I request the information:

    Code:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%--
    <%@taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
    --%>
    <%@taglib prefix="s" uri="/struts-tags" %>
    <!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=UTF-8">
            <title>Buscar Alumno </title>
        </head>
        <body>
            <h1>Busqueda de Alumno </h1>
            <s:form method="post" action="busca">
                <table>
                    <tbody>
                        <tr>
                            <td>Identificador</td>
                            <td><s:textfield key="alumno.id"/></td>
                        </tr>
                        <tr>
                            <td>Nombre</td>
                            <td><s:textfield key="alumno.nombre"/></td>
                        </tr>
                        <tr>
                            <td>Apellido</td>
                            <td><s:textfield key="alumno.apellido"/></td>
                        </tr>
                        <tr>
                            <td colspan="2"><s:submit value="Search Student"/></td>
                        </tr>
                    </tbody>
                </table>
            </s:form>
        </body>
    </html>
    This is my struts.xml:

    Code:
        <package name="default" namespace="/" extends="struts-default">
        </package>
        <package name="alumno" namespace="/alumno" extends="default">
            <action name="lista" class="alumnoAction" method="lista">
                <result>/WEB-INF/jsp/alumno/lista.jsp</result>
            </action>
            <action name="edita" class="alumnoAction" method="edita">
                <result>/WEB-INF/jsp/alumno/edita.jsp</result>
            </action>
            <action name="nuevo" class="alumnoAction" method="nuevo">
                <result name="input">/WEB-INF/jsp/alumno/nuevoAl.jsp</result>
                <result name="success" type="redirectAction">lista</result>
            </action>
            <action name="guarda" class="alumnoAction" method="guarda">
                <result name="input">/WEB-INF/jsp/alumno/edita.jsp</result>
                <result name="success" type="redirectAction">lista</result>
            </action>
            <action name="busca" class="alumnoAction" method="busca">
                <result name="input">/WEB-INF/jsp/alumno/buscaAl.jsp</result>
                <result name="success" type="redirectAction">Should I put a new JSP here?</result>
            </action>
    And these are my AlumnoAction and AlumnoDaoHibernate:


    Code:
    public class AlumnoAction extends ActionSupport {
        private static final Log log = LogFactory.getLog(AlumnoAction.class);
    
        @Resource(name="alumnoDaoHibernate")
        private AlumnoDao alumnoDao;
    
        private List<Alumno> alumnos;
    
        private Long id;
    
        private Alumno alumno;
    
        public String lista() {
            log.debug("Lista de alumnos desde struts");
            alumnos = alumnoDao.lista();
            return SUCCESS;
        }
    
        public String busca(){
            log.debug("Lista de alumnos desde struts utilizando busqueda opcional");
            alumnos = alumnoDao.listaPersonalizada(alumno.getId(), alumno.getNombre(), alumno.getApellido());
            return SUCCESS;
    
        }
    ....
    ....MORE CODE...
    Code:
      @Transactional(readOnly=true)
        public List<Alumno> listaPersonalizada(Long id, String nombre, String apellido)
        {
    
             String consulta2 = "FROM Alumno a WHERE a.id like '%"+ id +"%' and a.nombre like '%"+nombre+"%' and a.apellido like '%" + apellido + "'%'";
    
            return hibernateTemplate.find(consulta2);
        }

    I think I have to do a new JSP file using the information that I get after call to the search but I don't know how can I recover the information in a new JSP file when the accion busca() is completed.

    Thanks for all and sorry for my english...
    -Samuel-
Working...
X