0

従業員のリンクのリストがある jsp ページがあります。ユーザーがリンクをクリックすると、関連する emp_id がデータベースに送信され、emps の詳細が最終ビュー ページに表示されます。

そのため、ELを使用してそのempの詳細を表示しようとしており、その間に問題に直面しています..

これが私の最終的なビューページのコードです。

viewEmp.jsp

<%@page import="com.connection.util.*"%>
<%@page import="com.fulcrum.model.*"%>
<%@page import="java.sql.*"%>
<%@page import="com.fulcrum.service.FinalEmpRecords"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.util.ArrayList"%>
<%@page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<p style = "font-size: medium; color: green">
<%
if (request.getAttribute("success") != null) {
%>

<%=request.getAttribute("success")%>

<%
}
%></p>

<h3>Employee Details</h3>

<%!
Statement statement;
ResultSet resultEmpHobbies;
%>
<%
String id = request.getParameter("empcode");
Connection connect = ConnectionHandler.getConnection();
statement = connect.createStatement();

try{
    FinalEmpRecords viewEmp = new FinalEmpRecords();
    Employee emp=viewEmp.viewRecord(id);
    System.out.println ("empppppppp"+emp);
    request.setAttribute ("empobj", emp);
    Employee emphobbies=(Employee)request.getAttribute("empobj");
    String hobbies[]=emphobbies.getHobbies();

    request.setAttribute("hobbies", hobbies);
%>  

        ID : ${empobj.empcode}
        <br>
        <br>
        Name : ${empobj.fname} ${empobj.lname}
        <br>
        <br>
        age: ${empobj.age}
        <br>
        <br>
        email address : ${empobj.email}
        <br>
        <br>
        password : ${empobj.pwd}
        <br>
        <br>
        date of birth : ${empobj.date} ${empobj.month} ${empobj.year}
        <br>
        <br>
        Gender : ${empobj.gender}
        <br>
        <br>
        About Me : ${empobj.aboutMe}
        <br>
        <br>
        Hobbies
        <c:forEach items="hobbies" var="hobb">
         ${hobb.hobbies}
        </c:forEach>    
<%

} catch (Exception e) {
    System.out.println ("error");
    System.out.println (e.toString()+"<br>");
    e.printStackTrace();
}
%>

<br>
<br>
<%
if(request.getParameter("page") != null) {
%>
    <a href = 'welcomeEmp.jsp'> GO back Welcome page </a>
<%
} else {
%>
    <a href = 'welcomeEmp.jsp'> GO back Welcome page </a>
<%
}

%>
</body>
</html>

私のJavaクラス

FinalEmpRecords.java

   package com.fulcrum.service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;


import com.connection.util.ConnectionHandler;
import com.fulcrum.model.Employee;

public class FinalEmpRecords {
    private Statement statement;
    private Statement statement1;
    private ResultSet result;
    private ResultSet resultEmpHobbiesResult;
    String[] hobbies = new String[10];
    int counter = 0;

    public Employee viewRecord(String id) throws SQLException {
//      ConnectionHandler handler = new ConnectionHandler();
        ArrayList<String> listhobbies = new ArrayList<String>();
        Employee emp = new Employee();;
        System.out.println("id final view=" + id);
        try {
            Connection connect = ConnectionHandler.getConnection(); //handler.makeconnection();
            statement = connect.createStatement();
            statement1 = connect.createStatement();
            System.out.println("connection established");

            result = statement
                    .executeQuery("select emp_id,f_name,l_name,age,email_id,pwd,date,month,year,gender,aboutme from employee_validation.ev_employee where emp_id='"
                            + id + "'");

            while(result.next()) {
                System.out.println("in final while");

                emp.setEmpcode(result.getString(1));
                emp.setFname(result.getString(2));
                emp.setLname(result.getString(3));
                emp.setAge(result.getString(4));
                emp.setEmail(result.getString(5));
                emp.setPwd(result.getString(6));
                emp.setDate(result.getInt(7));
                emp.setMonth(result.getString(8));
                emp.setYear(result.getInt(9));
                emp.setGender(result.getString(10));
                emp.setAboutMe(result.getString(11));

                System.out.println("after final while");
            }

            resultEmpHobbiesResult = statement.executeQuery("SELECT hobbies.hobby_name FROM employee_validation.employee_hobbies,employee_validation.hobbies WHERE  employee_hobbies.hobby_id=hobbies.hobby_id AND employee_hobbies.emp_id='"+id+"'");

            while (resultEmpHobbiesResult.next()) {
                hobbies[counter] =  resultEmpHobbiesResult.getString(1);
                //listhobbies.add(e)
                System.out.println("hobbiessssss"+hobbies[counter]);
                counter++;

            }

            emp.setHobbies(hobbies);


        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println ("final emppp"+emp);



        return emp;

    }
}

このような詳細を印刷しようとすると、配列の値が空白になり、次の例外がスローされます。

error
javax.el.PropertyNotFoundException: Property 'hobbies' not found on type java.lang.String<br>
javax.el.PropertyNotFoundException: Property 'hobbies' not found on type java.lang.String
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
    at javax.el.BeanELResolver.property(BeanELResolver.java:325)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
    at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
    at org.apache.jsp.viewEmp_jsp._jspx_meth_c_005fforEach_005f0(viewEmp_jsp.java:238)
    at org.apache.jsp.viewEmp_jsp._jspService(viewEmp_jsp.java:172)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
4

1 に答える 1

2

For each loop 構文エラー。

変化する

  <c:forEach items="hobbies" var="hobb">
         ${hobb.hobbies}
        </c:forEach>   

  <c:forEach items="${hobbies}" var="hobb">
      <c:out value="${hobb}" /> 
   </c:forEach>    
于 2013-08-12T08:28:34.440 に答える