I'm not able to figure out this problem.
My error:
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 28
Line 28: <c:forEach items="${data.visit}" var="visit">
java class:
public class DataBean implements Serializable, ServletContextListener {
private static final String nameOfLogger = DataBean.class.getName();
private static final Logger logger = Logger.getLogger(nameOfLogger);
public class Visit {
public Visit(String dateOfTheVisit, String category, String idClient, String idInsrurer, String idDoctor, String idVisit,String accepted) {
this.dateOfTheVisit = dateOfTheVisit;
this.category = category;
this.idClient = idClient;
this.idInsrurer = idInsrurer;
this.idDoctor = idDoctor;
this.idVisit = idVisit;
this.accepted = accepted;
}
public String getIdVisit() {
return idVisit;
}
public void setIdVisit(String idVisit) {
this.idVisit = idVisit;
}
public String getDateOfTheVisit() {
return dateOfTheVisit;
}
public void setDateOfTheVisit(String dateOfTheVisit) {
this.dateOfTheVisit = dateOfTheVisit;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getIdClient() {
return idClient;
}
public void setIdClient(String idClient) {
this.idClient = idClient;
}
public String getIdInsrurer() {
return idInsrurer;
}
public void setIdInsrurer(String idInsrurer) {
this.idInsrurer = idInsrurer;
}
public String getIdDoctor() {
return idDoctor;
}
public void setIdDoctor(String idDoctor) {
this.idDoctor = idDoctor;
}
String idVisit;
String dateOfTheVisit;
String category;
String idClient;
String idInsrurer;
String idDoctor;
String accepted;
public String getAccepted() {
return accepted;
}
public void setAccepted(String accepted) {
this.accepted = accepted;
}
}
public class Insurer {
public Insurer(String idInsurer, String name) {
this.idInsurer = idInsurer;
this.name = name;
}
public String getIdInsurer() {
return idInsurer;
}
public void setIdInsurer(String idInsurer) {
this.idInsurer = idInsurer;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
String idInsurer;
String name;
}
//public List<Visit> visitArray = new ArrayList<>();
public List<Insurer> insurerArray = new ArrayList<>();
private java.sql.Connection psqlCon = null;
private boolean psqlConnectionCreated = false;
synchronized public ArrayList<Visit> getVisit() throws ClassNotFoundException, SQLException {
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "password");
Statement stm;
stm = conn.createStatement();
String sql = "Select * From Customer";
ResultSet rst;
rst = stm.executeQuery(sql);
ArrayList<Visit> visitArray = new ArrayList<>();
while (rst.next()) {
Visit visit = new Visit(rst.getString("dateOfTheVisit"), rst.getString("category"), rst.getString("idClient"), rst.getString("idInsurer"), rst.getString("idDoctor"), rst.getString("idVisit"),rst.getString("accepted"));
visitArray.add(visit);
}
return visitArray;
}
@Override
public void contextInitialized(ServletContextEvent sce) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
jsp:
<%@page import="java.util.List"%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<jsp:useBean id="data" class="sevenet.DataBean" scope="application"/>
<H1>The tableName Database Table </H1>
<TABLE BORDER="1">
<TR>
<TH>Date</TH>
<TH>Category</TH>
<TH>IdClient</TH>
<TH>IdInsurer</TH>
<TH>IdDoctor</TH>
<TH>Accepted</TH>
<TH>ID</TH>
</TR>
<tbody>
<c:forEach items="${data.visit}" var="visit">
<tr>
<td><c:out value="${visit.dateOfTheVisit}"/></td>
<td><c:out value="${visit.category}"/></td>
<td><c:out value="${visit.idClient}"/></td>
<td><c:out value="${visit.idInsrurer}"/></td>
<td><c:out value="${visit.idDoctor}"/></td>
<td><c:out value="${visit.idVisit}"/></td>
<td><c:out value="${visit.accepted}"/></td>
</tr>
</c:forEach>
</tbody>
</TABLE>
</BODY>
</HTML>
I'm not sure what I did wrong, but I think that it is something about the definition of the bean.
I appreciate every attempt to help!
5条答案
按热度按时间sirbozc51#
以下是我为让您的应用程序运行所做的工作。
FolderStructure(文件夹结构的图像)ApplicationExample(应用程序运行示例)
创建2个新Java包
(1)小服务程序(2)列表
添加2个类到列表(1)Visit.java(2)VisitListVariables.java添加1个类到Servlet(1)Servlet. java
Inside Visit.java
Inside VisitListVariables.java
Inside Servlet.java
在jsp中,我将其命名为test.jsp
Web.xml(通常您会有一个带有链接
<a href='/Servlet'>Visits</a>
的索引页,它指向您的servlet,但是为了进行测试,您可以将servlet键入url//localhost:8080/ProjectName/Servlet)cqoc49vn2#
Your code is quite tricky!!
1)Who is the caller of the method getVisit()? 2) Why you created a DataBean class with inner classes declared inside? 3) You are returning a ArrayList visitArray = new ArrayList<>(), and not a DataBean!
So, first of all, the DataBean class is useless Secondly, in the Visit class, don't just use a Insrured id, but use a instance of Insurer. this is the code examples:
}
public class Insurer {
}
Now you should create a servlet to show the datas, check this tutorial: http://www.mkyong.com/servlet/a-simple-servlet-example-write-deploy-run/
NOTICE THAT in the class ServletDemo1 the method name must be doGet (and not doGe, it was a simple digit error).
So, in your ServletDemo1, in the doGet method, you must do the same logic of your your getVisit(), then, before the return, you have to add this:
and instead o returning the list, dispatch to the your jsp path like this:
Now, in your jsp, delete
and correct the for each like this:
and instead of
put
I did not tried the code, but if you have any question do not hesitate to ask!
v8wbuo2f3#
Firstly, thank you very much for your answers. I have modified the code according to the first answer, but i got some trouble.
java:
servlet:
jsp:
How to declare BuildSearch()? What should be in this method?
Servlet can not find symbol visit, how to fix it? I know that this can be basic issues, but it is my first java project with database, web service..
guicsvcw4#
You need to use a servlet to get and send data to the jsp and set session variables. use your class to do your logic.
create a separate getter and setter class for each list
In New class
Visit class
}
//In New Servlet Put the visit in the session and you can get it with JSTL.
Your jsp
kx7yvsdv5#
使用getter代替,如**<c:out value="${visit.getDateOfTheVisit()}"/>**