• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 889
  • Last Modified:

JSP page method call problem

Hi,

im trying to do perform the method call in jsp where im tring to print the columns of the table.
but i don't know what is wrong with my code im getting the error message saying( Syntax error on tokens, delete these tokens )

code :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"   pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*, java.sql.*" %>
<%@page import="com.dash.DefectDetails"%>
<html>
<head>
<title> Defect details </title>
</head>
<body>
<jsp:include flush="true" page="./Header.jsp"/>
<center><table><tr><td><font size="5" color="#1B3F8B" face="Verdana"><b> Defect Details </b></td></tr></table></center>
<br>
<%! int numPages = 0;
      public void columns(Object d1 ){
            DefectDetails d = (DefectDetails)d1;
            String s = d.getTechMStatus();
            if (s.equalsIgnoreCase("Open")) { %>
            <TR style="background-color:#CC3300;border-color:#91B8E3"/>

            <% } else if (s.equalsIgnoreCase("Closed")) { %>
                  <TR style="background-color:#CCFFCC;border-color:#91B8E3">

            <% } else if (s.equalsIgnoreCase("Known Error")) { %>
                  <TR style="background-color:#CCCC99;border-color:#91B8E3">

            <% } else if (s.equalsIgnoreCase("Fixed")) { %>
                  <TR style="background-color:#FFCC66;border-color:#91B8E3">

            <% } else if (s.equalsIgnoreCase("Solving")) { %>
                  <TR style="background-color:#CC0000;border-color:#91B8E3">
            <% } %>

            <% if(d.getDefectId() != null){ %>
            <TD><font size="2" face="Verdana"><%=d.getDefectId()%></TD>
            <% } else { %>
            <TD><font size="2" face="Verdana"></TD>
            <% } %>

            <% if(d.getTechMStatus() != null){ %>
            <TD><font size="2" face="Verdana"><%=d.getTechMStatus()%></TD>
            <%}else{ %>
            <TD><font size="2" face="Verdana"></TD>
            <%}%>

            <% if(d.getSeverity() != null){ %>
            <TD><font size="2" face="Verdana"><%=d.getSeverity()%></TD>
            <%}else{ %>
            <TD><font size="2" face="Verdana"></TD>
            <%}%>

            <% if(d.getDescription() != null){ %>
            <TD><font size="2" face="Verdana"><%=d.getDescription()%></TD>
            <%}else{ %>
            <TD><font size="2" face="Verdana"></TD>
            <%}%>

            <% if(d.getRaisedBy() != null){ %>
            <TD><font size="2" face="Verdana"><%=d.getRaisedBy()%></TD>
            <%}else{ %>
            <TD><font size="2" face="Verdana"></TD>
            <%}%>

            <% if(d.getComments() != null){ %>
            <TD><font size="2" face="Verdana"><%=d.getComments()%></TD>
            <%}else{ %>
            <TD><font size="2" face="Verdana"></TD>
            <%}%>
      </TR>
<% } %>

<%
      try{
            String columnName = "";
            int count = 0;
            int increment = 1;
            int numRows = 0;
            int numRecordsPerPage = 5;
            String startIndexString = request.getParameter("startIndex");
            String option = request.getParameter("option");
            if(option == null){
                  option = "all";
            }
            System.out.println("==================="+option);
            if(startIndexString == null) {
                  startIndexString = "0";
            }
            int startIndex = Integer.parseInt(startIndexString);
            Vector vector = (Vector) session.getAttribute("defects11");
            Iterator itrvector = vector.listIterator();
            numRows = vector.size();
            numPages = numRows /numRecordsPerPage;
            int remain = numRows % numRecordsPerPage;
                  if(remain != 0){
                        numPages = numPages +1;
                  }%>
      <%
            if((startIndex + numRecordsPerPage) <= numRows) {
                  increment = startIndex + numRecordsPerPage;
            }
            else{
                  if (remain == 0){
                        increment = startIndex + numRecordsPerPage;
                  }else{
                        increment = startIndex + remain;
                  }
            } %>
            <table align = "center">
            <tr><td><form action = "Defect_Details.jsp" >
                        <select name="option" style="width:122px; font-size:10px;">
                              <option value="all">All Defects</option>
                              <option value="Closed">Closed Defects</option>
                              <option value="Open">Open Defects</option>
                              <option value="Know Errors">Know Errors</option>
                              <option value="AC">AC</option>
                        </select>
                              <button type = "submit"> send </button>
                        </form></td>
            <td><font size="3" color="#663300" face="Verdana"><b> Total Number of Records : <%= numRows %></b></font></td>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td><font size="3" color="#663300" face="Verdana"><b> Number of Records per Page : <%= numRecordsPerPage %></b></font></td>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td><font size="3" color="#663300" face="Verdana"><b> Number of Pages : <%= numPages %></b></font></td></tr>
            </table><br>
            <table align="center" cellspacing = "3" cellpadding="1" border="0" style="background-color: #C68E17; border-color:#91B8E3;">
            <TR>
                  <TD><font size="2" color="#1B3F8B" face="Verdana"><center><b>Defect Id</b></center></font></TD>
                  <TD><font size="2" color="#1B3F8B" face="Verdana"><center><b>TechM Status</b></center></font></TD>
                  <TD><font size="2" color="#1B3F8B" face="Verdana"><center><b>severity</b></center></font></TD>
                  <TD><font size="2" color="#1B3F8B" face="Verdana"><center><b>Description</b></center></font></TD>
                  <TD><font size="2" color="#1B3F8B" face="Verdana"><center><b>Raised By</b></center></font></TD>
                  <TD><font size="2" color="#1B3F8B" face="Verdana"><center><b>comments</b></center></font></TD>

            </TR>
            <%
                  com.dash.DefectDetails d = null;
                  String s = null;
                        if ( option.equalsIgnoreCase("ALL")) {
                              System.out.println("===========1============");
                              for(count = startIndex; count < increment; count++) {
                                    d = (com.dash.DefectDetails) vector.elementAt(count); %>
                                    <%= columns(d) %>
                              <% } } %>

            <%      if ( option.equalsIgnoreCase("Open")) {
                        for(int i =0 ; i <= numRows ; i++) {
                              d = (com.dash.DefectDetails)itrvector.next();
                              System.out.println("===========2============");
                              if(d.getTechMStatus().equalsIgnoreCase(option)) { %>
                                    <%= columns(d) %>
                              <% } } } %>
      
</table><br>
<table align = "center">
      <tr>
            <td>
                  <%if(startIndex != 0) {%>
                  <font size="3" color="#8E35EF" face="Verdana"><b>
                  <a href="Defect_Details.jsp?startIndex=<%=startIndex-numRecordsPerPage%>">Previous</a></b></font>
                  <%}%>
            </td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td>
                  <font size="3" color="#FFFFFF" face="Verdana"><b>Displaying Records:
                  <% if(startIndex + numRecordsPerPage < numRows){%>
                  <%= " " + startIndex %> - <%= increment - 1 %>
                  <%}else{%>
                  <%= " " + startIndex %> - <%= numRows %>
                  <%}%></b></font>
            </td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td>
                  <%increment += numRecordsPerPage;%>
                  <%if((startIndex + numRecordsPerPage < numRows) & (startIndex<=numRows)){%>
                  <font size="3" color="#8E35EF" face="Verdana"><b>
                  <a href="Defect_Details.jsp?startIndex=<%=startIndex+numRecordsPerPage %>">Next</a></b></font>
                  <%}%>
            </td>
      </tr>
</table><br><br>
<% }  catch(Exception exc){
      out.println(exc.toString());
      exc.printStackTrace();
      } %>
</body>
</html>

please can any one help me out.

Regards,
Nyamath khan.
0
Nyamathkhan
Asked:
Nyamathkhan
  • 8
  • 6
  • 2
1 Solution
 
ioantonCommented:
First of all, replace the character '!' from the line:

<%! int numPages = 0;
0
 
ioantonCommented:
Sorry, remove it.
0
 
NyamathkhanAuthor Commented:
hi,

i have did that but still im getting the problem at the location

if (s.equalsIgnoreCase("Open")) { %>
      <TR style="background-color:#CC3300;border-color:#91B8E3">

      <% } else if (s.equalsIgnoreCase("Closed")) { %>

Problem :
Syntax error on tokens, delete these tokens

Regards,
Nyamathkhan
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
anilallewarCommented:
Removing the ! won't work if you want a separate method that you want to call from the generated servlets service() method.

The problem is happening because your columns() method is a hash of JSP declarations and statement; hence half the code(actually till the first ending %> after the <%!) goes in your columns() method while the rest goes to the service method.

There are 2 options
1. Convert all the HTML call within the columns() method and replace with out.println(). SInce the implicit objects are NOT available to the methods other than service() you will have to pass the JSPWriter object to the columns(Object d1, JSPWriter out).
2. Write a custom tag to take up this functionality.
0
 
NyamathkhanAuthor Commented:
Hi,
 i have tried with jspwriter and its getting the exception in the server console.

269:                               String status = (String)d.getTechMStatus();
270:                               if(status.equalsIgnoreCase(option)) {
271:                                     k++; %>
272:                               <%= columns(d, out1) %>
273:                   <% } } if (k == 0) {
274:                               System.out.println("===========3============");
275:                               out1.print("<font size='2' face='Verdana'><b> No Open Defects ! </b></font>"); %>

added the method in jsp :

<%!
      public void columns( Object o, JspWriter out) throws Exception {
      DefectDetails d = (DefectDetails)o;
      String s = (String)d.getTechMStatus();
            if (s.equalsIgnoreCase("Open")) {
            out.print("<TR style='background-color:#CC3300;border-color:#91B8E3'>");

            } else if (s.equalsIgnoreCase("Closed")) {
            out.print("<TR style='background-color:#CCFFCC;border-color:#91B8E3'>");

            } else if (s.equalsIgnoreCase("Known Error")) {
            out.print("<TR style='background-color:#CCCC99;border-color:#91B8E3'>");

            } else if (s.equalsIgnoreCase("Fixed")) {
            out.print("<TR style='background-color:#FFCC66;border-color:#91B8E3'>");

            } else if (s.equalsIgnoreCase("Solving")) {
            out.print("<TR style='background-color:#CC0000;border-color:#91B8E3'>");

                  }if(d.getDefectId() != null){
                  out.print("<TD><font size='2' face='Verdana'>"+d.getDefectId()+"</td>");
                  } else {
                  out.print("<TD><font size='2' face='Verdana'></td>");

                  }if(d.getTechMStatus() != null){
                  out.print("<TD><font size='2' face='Verdana'>"+d.getTechMStatus()+"</td>");
                  } else {
                  out.print("<TD><font size='2' face='Verdana'></td>");

                  }if(d.getSeverity() != null){
                  out.print("<TD><font size='2' face='Verdana'>"+d.getSeverity()+"</td>");
                  } else {
                  out.print("<TD><font size='2' face='Verdana'></td>");

                  }if(d.getDescription() != null){
                  out.print("<TD><font size='2' face='Verdana'>"+d.getDescription()+"</td>");
                  } else {
                  out.print("<TD><font size='2' face='Verdana'></td>");

                  }if(d.getRaisedBy() != null){
                  out.print("<TD><font size='2' face='Verdana'>"+d.getRaisedBy()+"</td>");
                  } else {
                  out.print("<TD><font size='2' face='Verdana'></td>");

                  }if(d.getComments() != null){
                  out.print("<TD><font size='2' face='Verdana'>"+d.getComments()+"</td>");
                  } else {
                  out.print("<TD><font size='2' face='Verdana'></td>");

            }
            out.println("</TD>"); }
      %>
0
 
NyamathkhanAuthor Commented:

sorry forgot the error message :

An error occurred at line: 272 in the jsp file: /Defect_Details.jsp
The method print(boolean) in the type JspWriter is not applicable for the arguments (void)
0
 
anilallewarCommented:
You are calling a expression but your method returns void; that why the error.

Change the function call on line 272 to <% columns(d, out1); %>

0
 
NyamathkhanAuthor Commented:
hi,
ya ur right ! it is working fine now.
thanks a lot !

Regards,
Nyamathkhan.
0
 
anilallewarCommented:
If you are satisfied with the answer; can you please allocate points and close the question?
0
 
NyamathkhanAuthor Commented:
done
0
 
anilallewarCommented:
The points are still NOT awarded neither is the answer accepted!!
0
 
NyamathkhanAuthor Commented:
hi already alloted the point and accepted the answer also.

any way i have did that again. hope this time it will work.

Regards,
nyamath.
0
 
anilallewarCommented:
@Nyamathkhan, id did NOT work this time too :)

Can you please raise this with EE moderator as to why this is not happening?
0
 
NyamathkhanAuthor Commented:
anilallewar : i have did it twice. but even thought its not gettig assign u the points. then what can i do ?

Regards,
Nyamath.
0
 
anilallewarCommented:
Nyamath,

You would find a "Request Attention" link at the bottom right band side of the question before the comments start. You can use that link to bring this problem to the attention of EE.

Anil
0
 
NyamathkhanAuthor Commented:
the solution provided was complete
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 8
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now