Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java Open Source > Struts
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Struts section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2007, 04:24 AM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Blank Struts page after submit

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>
<%}%>
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>
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");
    }
}
 
Old February 14th, 2007, 02:37 AM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check the words success --- succes
return mapping.findForward("success"); // On Action

<forward name="succes" path="/pages/DatePersonal.jsp" redirect="true"/> // on Struts-config.xml




 
Old August 28th, 2007, 12:46 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1 You can write execute method instead of perform method.
2. Many times what happen we forget to override execute method so controller execute inherited execute method and displays blank page.
3. Check the forward strings such as "succes" / "failure".

sbgaikwad





Similar Threads
Thread Thread Starter Forum Replies Last Post
Blank Default Page ghrebek BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 8 December 5th, 2006 08:09 PM
How to submit repeated data in formbean in struts somnathp Struts 0 July 26th, 2005 12:37 AM
Submit repeated data item in a form using Struts somnathp Javascript How-To 0 July 26th, 2005 12:34 AM
why blank page? gilgalbiblewheel Classic ASP Databases 6 December 31st, 2004 09:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.