struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simion Ursache" <simion.ursa...@gmail.com>
Subject Blank Struts Page after Submit
Date Sat, 03 Feb 2007 08:11:56 GMT
Hi !

I am learning to work with struts, after i click on submit button (in a
form) i get a blank page. This thing is annoying me because i can't find the
solution for a week !

The page has 2 hmtl list option. The first list loads info about a company
compartiments, and after hitting "Refresh Employees", the second list should
shouw data about all the employees from the selected department.

What is happening ? After hitting "Refresh Employees" i get a blank
selectAngajat.do page. If i go Back and Refresh(F5) the second list option
shows all the employees from that department.

Does anyone have any idea about this ? I posted some code down:

PersonalBody.jsp
[code]
<%@ page import="databeans.*"%>
<%@ page import="java.sql.Connection"%>
<jsp:useBean id="ss_PersSelected" class="databeans.CompartPersSelectedBean"
scope="session"/>
<html:form action="/selectAngajat.do">
<table width="600" border="1">
<tr>
<td width="174">Selectati un Compartiment:</td>
<td width="213">
<html:select property="compartid">
<%
Connection conn=Utilitati.getConexiune();
java.util.ArrayList listaCompartimente=
    ObiectPersistent.getObjects(Compartimente.class,conn,null);
conn.close();
for(int i=0;i<listaCompartimente.size();i++) {
%>
<html:option
value="<%=((Compartimente)listaCompartimente.get(i)).getCompartid()%>">
<%=((Compartimente)listaCompartimente.get(i)).getNumecompart()%>
</html:option>
<%}%> <%-- s-a inchis for-ul--%>
</html:select>

</td>
<td width="191">
<input type="submit" name="Submit" value="Refresh Employees">
</td>
</tr>
<tr>
<td width="174">Selectati Angajatul:</td>
<td width="213">
<html:select property="marcaselectata">
<% Connection conn=Utilitati.getConexiune();
if (ss_PersSelected.getCompartid() != null) //exista un compartiment
selectat
{ java.util.ArrayList listaAngajati =
    ObiectPersistent.getObjects(Personal.class,conn,
" where compartid='"+ss_PersSelected.getCompartid()+"' ");
conn.close();
for(int i=0;i<listaAngajati.size();i++){%>
<html:option
value="<%=((Personal)listaAngajati.get(i)).getMarca().toString()%>">
<%=((Personal)listaAngajati.get(i)).getNumepren()%>
</html:option>
<%}}%> <%-- inchidem FOR si IF --%>
</html:select>
</td>
<td width=" 191 ">
<input type="submit" name="Submit2" value="Show Employee">
</td>
</tr>
</table>

</html:form>

<%if (request.getSession().getAttribute("ss_DatePers") != null){%>
<tiles:insert page="/tiles/bodys/DateAngajatBody.jsp"/> <%}
    else if (ss_PersSelected.getCompartid() != null){%>
    <html:form action="/dateAngajat.do">
<html:hidden property="actiune" value="newObject"/>
<html:submit property="add" value="Angajat Nou" />
</html:form>
<%}%>
[/code]

struts-config.xml
[code]
<struts-config>

<form-beans>
    <form-bean name="loginBean" type="databeans.LoginExistingUserForm"/>
        <form-bean name="ss_PersSelected" type="
databeans.CompartPersSelectedBean"/>
 <form-bean name="ss_DatePers" type="databeans.Personal"/>
</form-beans>

<action-mappings>
<action path="/selectAngajat" type="formactions.SelectAngajatAction"
name="ss_PersSelected" input="/tiles/bodys/PersonalBody.jsp"
scope="session">
<forward name="succes" path="/pages/DatePersonal.jsp" redirect="true"/>
</action>
</action-mappings>
</struts-config>
[/code]

SelectAngajatAction.class
[code]
package formactions;

import databeans.CompartPersSelectedBean;

import databeans.ObiectPersistent;
import databeans.Personal;
import databeans.Utilitati;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class SelectAngajatAction extends Action {

    public ActionForward perform(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws
IOException,

ServletException {
        CompartPersSelectedBean formBean = (CompartPersSelectedBean)form;
        java.sql.Connection conn = null;

        if (formBean.getMarcaselectata() != null &&
            formBean.getMarcaselectata().intValue() != -1)
            try { // incarc in sesiune obiectul Personal corespunzator
marcii selectate de utilizator
                conn = Utilitati.getConexiune();
                Personal objPersCurent =
                    (Personal)ObiectPersistent.getObjects(Personal.class,
conn,
                                                          "where marca=" +

formBean.getMarcaselectata().toString()).get(0);
                // ATENTIE! Identificatorul atributului trebuie sl fie cel
definit in Struts-Contig.xml
                request.getSession().setAttribute("ss_DatePers",
                                                  objPersCurent);


                conn.close();

            } catch (Exception e) {
                e.printStackTrace();
                if (conn != null)
                    try {
                        conn.close();
                    } catch (Exception err) {
                    err.printStackTrace();
                    }
                return mapping.findForward("eroareBD");
            }
        else // daca marca e null elimin eventualul atribut ss_DatePers
anterior
            request.getSession().removeAttribute("ss_DatePers");

        return mapping.findForward("success");
    }
}
[/code]

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message