So beziehen Sie sich auf Benutzerfunktionen von der JSP-Seite
Frage
Ich habe einen einfachen Helfer gezeichnet, der einen Hyperlink vom Namen des Controllers, des Action-Names und der Parameterliste erzeugt. generasacodicetagpre.
und ich rufe es auf der JSP-Seite an: generasacodicetagpre.
und die Ausnahme wird angehoben, wenn die Webseite angezeigt wird.Was soll ich beheben, um meine Helferfunktion zu verwenden?
Ausnahmetext: generasacodicetagpre.
Lösung 2
I've found the way out with the problem. The JSP is looking in the following way:
<%@page import="com.epam.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">
<!-- The following line defines the type of the item variable -->
<jsp:useBean id="item" type="com.ACME.mvc3.model.Topic"/>
<tr>
<!-- The following line doesn't need curly braces -->
<td height="20"><p><%=Utils.actionLink(item.getName(), "topic", "details") %></p></td>
</tr>
</c:forEach>
Andere Tipps
A better way would be to use JSTL functions.
You should just define it in WEB-INF/yoursite.tld
:
<function>
<name>escape</name>
<function-class>com.foo.util.WebUtils</function-class>
<function-signature>String escape(java.lang.String)</function-signature>
</function>
And then you can use it as ${ys:escape(str)}
(after importing the namespace. Look for any .tld file to see how the rest of it looks like)