开发者

org.apache.jasper.JasperException: Unable to compile class for JSP: [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to upload files in JSP/Servlet?

I am using tomcat 6.0 I have the following jsp code

 <%@ page import="java.util.*" %>
 <!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
 <html>
 <head>
 </head> 
 <body> 
 <table>
 <tr>
 <td>Name</td>
 <td>Start Date</td>
 </tr>
 <%
 List<data> da1 = conb.dat();
 while(da1 != null) {
 %>
<tr>
<td><%out.print(da1.get1());%></td>
<td><%out.print(da1.get2());%></td>
</tr>
<%
}
%>
</table>            
</body> 
</html>

and i am getting this error

 org.apache.jasper.JasperException: Unable to compile class for JSP: 

 An error occurred at line: 68 in the jsp file: /trands.jsp
 The method get1() is undefined for the type List<data>
 65: <%
 66: data da = new pkg.data();
 67: List<data> da1 = conb.dat();
 68: while(da1 != null) {
 69: %>
 70:     <tr>
 71:     <td><%out.print(da1.get1());%>&开发者_运维问答lt;/td>


 An error occurred at line: 69 in the jsp file: /trands.jsp
 The method get2() is undefined for the type List<data>
 66: data da = new data();
 67: List<data> da1 = conb.dat();
 68: while(da1 != null) {
 69: %>
 70:     <tr>
 71:     <td><%out.print(da1.get1());%></td>
 72:     <td><%out.print(da1.get2());%></td>


 Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:        92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

java files are in WEB-INF/classes/pkg folder why am i getting this error. and why its showing that get1() is undefined. i have get1() function in data.java. connectdb() is jdbc java file). I have compiled all the java class to get the .class files. and will this while loop show me all the details of my database

CODE FOR data.java

 package pkg;

 public class data
 {  
public String propn;
public String startd;
 public data()
{
}
public void set1(String a)
{
propn=a;
}
public String get1()
{
return propn;
}
public void set2(String b)
{
startd=b;
}
public String get2()
{
return startd;
}
}


The List interface does not have get1() and get2() methods. All it has is a get() method. Perhaps you intended to use that instead:

<td><%out.print(da1.get(1));%></td>
<td><%out.print(da1.get(2));%></td>

Note that the list index starts with 0, not 1. Perhaps you'd like to change that as well.

See also:

  • Java Collections Tutorial

Unrelated to the concrete problem, I have no idea what you're trying to do, but I would only mention that this code is a disaster and exposes more other problems (to start, what did you think to achieve with while (da1 != null)? did you want to show them in an infinite loop?). I'd strongly recommend to forget JSP for this bit and move all the work to a normal Java class which you in turn test as normal Java application with a main() method which prints the results by System.out.println(). That's much easier developing, playing and testing. Once you got it all to work, then you can import and call that class in a servlet which ultimately lets the JSP display the results.


Update:

Here's how you would normally like to loop over a list (I've fixed the terrible naming conventions for you based on best guesses so that the code is more self-documenting):

List<Work> works = workService.list();

for (Work work : works) {
    System.out.println(work.getPropertyNumber());
    System.out.println(work.getStartDate());
}

And here's how you would normally loop over it in a JSP

<c:forEach items="${works}" var="work">
    <td>${work.propertyNumber}</td>
    <td>${work.startDate}</td>
</c:forEach>


The da1 variable is of type List. It does not contain method get1() and get2(). What you probably want is da1.get(1), da1.get(2) etc.

<%out.print(da1.get(1));%>
<%out.print(da1.get(2));%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜