Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSTL标记从数据类在JSP中打印_Java_Html_Jsp_Web Applications_Jstl - Fatal编程技术网

Java JSTL标记从数据类在JSP中打印

Java JSTL标记从数据类在JSP中打印,java,html,jsp,web-applications,jstl,Java,Html,Jsp,Web Applications,Jstl,我有一个业务层类来管理一些数据。有一种方法可以在包含JSTL标记的代码中生成HTML代码 <h1 id=\"infoMsg\"><fmt:message key=\"uebersicht.infomsg\" /></h1> 此代码将包含在JSP文件中 像这样: <%=bl.getMessages()%> <c:out value="${bl.getMessages()}"/> <% MessageBL bl = new

我有一个业务层类来管理一些数据。有一种方法可以在包含JSTL标记的代码中生成HTML代码

<h1 id=\"infoMsg\"><fmt:message key=\"uebersicht.infomsg\" /></h1>

此代码将包含在JSP文件中 像这样:

<%=bl.getMessages()%>
<c:out value="${bl.getMessages()}"/>
<% MessageBL bl = new MessageBL(); %>
??? no information!! ???

<h1 id="infoMsg">???
no information!!
???</h1>

但是这样它将作为HTML请求被包含,但是还有其他方法包含方法中的代码吗 例如:

<%=bl.getMessages()%>
<c:out value="${bl.getMessages()}"/>
<% MessageBL bl = new MessageBL(); %>
??? no information!! ???

<h1 id="infoMsg">???
no information!!
???</h1>

将其包含在JSP文件中的最简单方法是使用您提供的代码(假设该方法返回HTML格式的字符串):


此代码:

<c:out value="${bl.getMessages()}"/>

将不起作用,因为您在JSP scriplet中声明了对象,如下所示:

<%=bl.getMessages()%>
<c:out value="${bl.getMessages()}"/>
<% MessageBL bl = new MessageBL(); %>
??? no information!! ???

<h1 id="infoMsg">???
no information!!
???</h1>


原因是,scriplet中声明的JSP对象无法从EL表达式访问。

我没有找到任何解决方案。因此,我找到了一个解决办法:

<!-- set whole HTML source -->
<c:set var="message" value="${bl.messages}"></c:set>
<!-- set the key from a propertie file on a variable -->
<fmt:message key="uebersicht.infomsg" var="info"/>
<!-- get first part before the fmt tag -->
<c:set var="erst" value="${fn:substringBefore(message, '<fmt:message key')}" scope="application" />
<!-- get second part after the fmt tag -->
<c:set var="zweit" value="${fn:substringAfter(message, 'uebersicht.infomsg\" />')}" />
<!-- connect the three parts (first - key varible - second) -->
<fmt:message key="${fn:replace(erst,'?','')}"/>
${info}
<fmt:message key="${zweit}"/>

')}" />
${info}
它可以工作,但两个部分显示问号,输出如下:

<%=bl.getMessages()%>
<c:out value="${bl.getMessages()}"/>
<% MessageBL bl = new MessageBL(); %>
??? no information!! ???

<h1 id="infoMsg">???
no information!!
???</h1>
???没有信息???
???
没有消息!!
???

我如何替换问号?

你能详细说明你的问题吗?我真的不明白你想要解决的问题。
会更合适。好的。MessageBL类的定义类似于
,我想包括h1标记的HTML代码。此方法将代码作为字符串返回。我必须定义
bl 另一种方式?我用这个标签试过了,但问题是JSTL标签
为什么
如果我在JSP中编写,它会工作,但是如果我从另一个类中获取源代码并包含它,它就不工作了。之后你可以在网站的源代码中看到JSTL标签。