Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 索引页不会与servlet对话_Java_Jsp_Servlets - Fatal编程技术网

Java 索引页不会与servlet对话

Java 索引页不会与servlet对话,java,jsp,servlets,Java,Jsp,Servlets,谁能帮帮我吗。我似乎无法找到为什么索引页不与servlet对话。我只是尝试使用doGet()方法,它甚至不会打印出我放置的system.out INDEX.JSP 您的表单中没有任何输入或选择标记。你甚至没有提交按钮。那么,您认为表单将如何做任何事情呢?是什么让您认为表单可以使用Get方法呢?是什么促使表单打电话?我只是想从数据库中加载一个人员列表。我不能使用索引页获取使用get方法的人员列表吗?如果有更好的方法,我很想知道。为了解决这个问题,我已经在桌子上敲了好几个小时的头。这可以解决post

谁能帮帮我吗。我似乎无法找到为什么索引页不与servlet对话。我只是尝试使用doGet()方法,它甚至不会打印出我放置的system.out

INDEX.JSP
您的
表单中没有任何
输入
选择
标记。你甚至没有提交按钮。那么,您认为表单将如何做任何事情呢?是什么让您认为表单可以使用Get方法呢?是什么促使表单打电话?我只是想从数据库中加载一个人员列表。我不能使用索引页获取使用get方法的人员列表吗?如果有更好的方法,我很想知道。为了解决这个问题,我已经在桌子上敲了好几个小时的头。这可以解决post的问题。对于get问题,您将向后思考。按照您编写这篇文章的方式,您应该先转到servlet,然后再转到servlet,然后再转发到JSP?
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="java.util.ArrayList" %>
     <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
     <%@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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add a Customer/Pet</title>
</head>
<body>
<h1>List of Customers</h1>
    <form method="get" action="fetchDataServlet">
    <c:forEach items="${sessionScope.customers}" var="customer">
        <ul>
            <li>${customer.getFirstName()}</li>
        </ul>           
    </c:forEach>

</form>
</body>
</html>
package edu.witc.Assignment05.controller;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;




import javax.servlet.http.HttpSession;

import edu.witc.Assignment05.model.Customer;
import edu.witc.Assignment05.model.CustomerDAO;




@WebServlet(description = "servlet to get act as controller between form and models", urlPatterns = { "/fetchDataServlet","/addCustomer","/addPet", "/customerManagement" })
public class FetchDataServlet<T> extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public FetchDataServlet() {
        super();
    }

    @Override
    public void init() throws ServletException {
System.out.print("INIT");     
    }

    private List<edu.witc.Assignment05.model.Customer> customers = new ArrayList<Customer>();


    private void addCustomer(HttpServletResponse response, HttpServletRequest request)//redirect to form
            throws IOException, ServletException {
            String url = "/customerManagement.jsp";
            //processRequest(request, response);
            Customer customer = new Customer();
            HttpSession session = request.getSession();
            session.setAttribute("customer", customer);
            request.getRequestDispatcher(url).forward(request,response);
     }

    private void addPet(HttpServletResponse response, HttpServletRequest request)//redirect to pet page
         throws IOException, ServletException {
         String url = "/pets.jsp";
         request.getRequestDispatcher(url).forward(request,response);
    }




    public void doGet(HttpServletRequest request, 
            HttpServletResponse response)
            throws ServletException, IOException {
           HttpSession session = request.getSession();
           System.out.println("MADE IT");
           CustomerDAO<T> dao;
        try {

            dao = new CustomerDAO<T>();
            customers = dao.getData();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


               request.setAttribute("customers", customers);
               System.out.println(customers.size());
               String url = "/index.jsp";
            request.getRequestDispatcher(url).forward(request,response);

    }

    public void doPost(HttpServletRequest request, 
            HttpServletResponse response)
            throws ServletException, IOException {
         System.out.println("IN THE POST");

        int customerId = 0;
        Customer customer = new Customer();

        if (customer != null) {
            customerId = customers.size()+1;
            customer.setCustomerId(customerId);
            customer.setFirstName(request.getParameter("firstName"));
            customer.setLastName(request.getParameter("lastName"));
            customer.setEmailAddress(request.getParameter("email"));
            customer.setPhoneNumber(request.getParameter("phone"));
            customers.add(customer);



        }

    }
}
Apr 30, 2014 5:23:13 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\nodejs\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\RailsInstaller\Git\cmd;C:\RailsInstaller\Ruby1.9.3\bin;C:\Users\esder_000\AppData\Roaming\npm;.
Apr 30, 2014 5:23:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Justin_EJ_Assignment05_15400579' did not find a matching property.
Apr 30, 2014 5:23:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Justin_EJ_Assignment02_15400579' did not find a matching property.
Apr 30, 2014 5:23:13 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Apr 30, 2014 5:23:13 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Apr 30, 2014 5:23:13 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 643 ms
Apr 30, 2014 5:23:13 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 30, 2014 5:23:13 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
Apr 30, 2014 5:23:14 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Apr 30, 2014 5:23:14 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Apr 30, 2014 5:23:14 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1145 ms