Note that there are some explanatory texts on larger screens.

plurals
  1. POjavax.servlet.jsp.JspException: Cannot find bean: "departments" in any scope
    text
    copied!<pre><code>JSP PAGE &lt;%-- Document : DeptListing Created on : 20-Aug-2011, 10:12:36 Author : LenasalonM01 --%&gt; &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%&gt; &lt;%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%&gt; &lt;%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;Department listing&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;%-- &lt;jsp:include page="Header.jsp"&gt; &lt;jsp:param name="header" value="Dept Listing"/&gt; &lt;/jsp:include&gt;--%&gt; &lt;table&gt; &lt;logic:iterate id="dept" name="departments"&gt; &lt;tr&gt; &lt;td&gt; &lt;bean:write name="dept" property="name" /&gt; &lt;/td&gt; &lt;td&gt; &lt;html:link page="/listEmployees.do" paramId="deptid" paramName="dept" paramProperty="id"&gt; show &lt;/html:link&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/logic:iterate&gt; &lt;/table&gt; &lt;%@include file="/Footer.jsp" %&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>FORM BEAN</p> <pre><code>/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.hrms; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; /** * * @author LenasalonM01 */ public class EmployeeForm extends org.apache.struts.action.ActionForm { public static final String EDIT_MODE = "edit"; public static final String DELETE_MODE = "delete"; public static final String ADD_MODE = "add"; String action; Employee employee; public EmployeeForm() { employee = new Employee(); action = EmployeeForm.ADD_MODE; } public Employee getEmployee() { return employee; } public void setEmployee(Employee employee) { this.employee = employee; } /** * Returns the action. * @return String */ public String getAction() { return action; } /** * Sets the action. * @param action The action to set */ public void setAction(String action) { this.action = action; } /** * @see org.apache.struts.action.ActionForm#reset(ActionMapping, HttpServletRequest) */ /** * */ @Override public void reset(ActionMapping mapping, HttpServletRequest request) { this.employee = new Employee(); this.action = ADD_MODE; } /** * This is the action called from the Struts framework. * @param mapping The ActionMapping used to select this instance. * @param request The HTTP Request we are processing. * @return */ @Override public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) { ActionErrors errors = new ActionErrors(); if ((employee.getFirstName() == null) || (employee.getFirstName().length() &lt; 3)) { errors.add("FirstName", new ActionMessage("error.employee.firstname")); } return errors; } } </code></pre> <p>DEPARTMENT ACTION</p> <pre><code>/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.hrms; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * * @author LenasalonM01 */ public class ListDepartmentsAction extends org.apache.struts.action.Action { /* forward name="success" path="" */ /** * This is the action called from the Struts framework. * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * @throws java.lang.Exception * @return */ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute("departments", Dept.getDepartments()); return mapping.findForward("listing"); } } </code></pre> <p>STRUTS-CONFIG</p> <pre><code>&lt;action input="/" name="EmployeeForm" path="/listEmployees" scope="request" validate="true" type="action.ListEmployeesAction"&gt; &lt;forward name="listing" path="/EmployeeListing.jsp"/&gt; &lt;/action&gt; &lt;action path="/listDepartments" scope="request" name="departments" validate="true" type="action.ListDepartmentsAction"&gt; &lt;forward name="listing" path="/DeptListing.jsp"/&gt; &lt;/action&gt; &lt;action path="/editEmployee" type="action.EditEmployeeAction" name="employeeForm" attribute="employeeForm" input="/EmployeeForm.jsp" scope="request" validate="true"&gt; &lt;forward name="form" path="/EmployeeForm.jsp"/&gt; &lt;/action&gt; &lt;action input="/EmployeeForm.jsp" name="employeeForm" action="action.UpdateEmployeeAction" path="/updateEmployee" scope="request" type="action.UpdateEmployeeAction"&gt; &lt;forward name="listing" path="/EmployeeListing.jsp"/&gt; &lt;/action&gt; &lt;!-- &lt;action input="/employee_registration.jsp" name="loginform" path="/login" type="com.hrms.formlogin"&gt; &lt;forward name="employee_reg" path="/register_employee.jsp"/&gt; &lt;/action&gt;--&gt; &lt;/action-mappings&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload