Я создал простой помощник, который выдает гиперссылку из имени контроллера, имени действия и списка параметров.
public static String actionLink(String text, String controller, String action, String[] args) {
String result, URI = "";
URI = controller + "/" + action + "/";
for (int i = 0; i < args.length; i++) {
URI = URI + args[i];
}
result = "<a href=\"" + URI + "\">" + text + "</a>";
return result;
}
И я вызываю функцию со страницы jsp:
<%@page import="com.ACME.mvc3.helpers.Utils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<c:forEach items="${model}" var="item">
<tr>
<td height="20"><p><%=Utils.actionLink( ${item.name}, "topic", "", ${item.id} )%></p></td>
</tr>
</c:forEach>
И исключение возникает, когда отображается веб-страница. Что я должен исправить, чтобы использовать мою вспомогательную функцию?
Текст исключения:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 26 in the jsp file: /WEB-INF/views/home.jsp
Syntax error, insert ")" to complete MethodInvocation
23: <td height="10"><hr width="100%" size="2" /></td>
24: </tr>
25: <tr>
26: <td height="20"><p><%=${Utils.actionLink(item.name, "topic", "", new String(item.id) )}%></p></td>
27: <td width = 10%>
28: </td>
29: </tr>
An error occurred at line: 26 in the jsp file: /WEB-INF/views/home.jsp
Syntax error, insert ";" to complete Statement
23: <td height="10"><hr width="100%" size="2" /></td>
24: </tr>
25: <tr>
26: <td height="20"><p><%=${Utils.actionLink(item.name, "topic", "", new String(item.id) )}%></p></td>
27: <td width = 10%>
28: </td>
29: </tr>
An error occurred at line: 26 in the jsp file: /WEB-INF/views/home.jsp
$ cannot be resolved to a variable
23: <td height="10"><hr width="100%" size="2" /></td>
24: </tr>
25: <tr>
26: <td height="20"><p><%=${Utils.actionLink(item.name, "topic", "", new String(item.id) )}%></p></td>
27: <td width = 10%>
28: </td>
29: </tr>
An error occurred at line: 26 in the jsp file: /WEB-INF/views/home.jsp
item.name cannot be resolved to a type
23: <td height="10"><hr width="100%" size="2" /></td>
24: </tr>
25: <tr>
26: <td height="20"><p><%=${Utils.actionLink(item.name, "topic", "", new String(item.id) )}%></p></td>
27: <td width = 10%>
28: </td>
29: </tr>
An error occurred at line: 26 in the jsp file: /WEB-INF/views/home.jsp
An anonymous class cannot subclass the final class String
23: <td height="10"><hr width="100%" size="2" /></td>
24: </tr>
25: <tr>
26: <td height="20"><p><%=${Utils.actionLink(item.name, "topic", "", new String(item.id) )}%></p></td>
27: <td width = 10%>
28: </td>
29: </tr>
An error occurred at line: 26 in the jsp file: /WEB-INF/views/home.jsp
item.id cannot be resolved to a type
23: <td height="10"><hr width="100%" size="2" /></td>
24: </tr>
25: <tr>
26: <td height="20"><p><%=${Utils.actionLink(item.name, "topic", "", new String(item.id) )}%></p></td>
27: <td width = 10%>
28: </td>
29: </tr>
An error occurred at line: 26 in the jsp file: /WEB-INF/views/home.jsp
Syntax error on token ")", { expected
23: <td height="10"><hr width="100%" size="2" /></td>
24: </tr>
25: <tr>
26: <td height="20"><p><%=${Utils.actionLink(item.name, "topic", "", new String(item.id) )}%></p></td>
27: <td width = 10%>
28: </td>
29: </tr>
An error occurred at line: 130 in the generated java file
Syntax error, insert "}" to complete Block
An error occurred at line: 130 in the generated java file
Syntax error, insert "while ( Expression ) ;" to complete BlockStatements