English 中文(简体)
OpenCMS: 如何使用 JSP/ Javascript/ Java 中的变量?
原标题:OpenCMS: How to use variables in JSP/Javascript/Java?

我有一个像这样的表格:

<form id="form" method="post">
    Name: <input name="name" />
    E-Mail: <input name="email"/>
    Comment: <textarea name="comment" cols="5" rows="10"></textarea>
    <input type="submit" name="submit" value="submit"/>
</form>

用于某些开发者博客的评论功能。 因此,我需要将输入的内容插入一些数据库,以便日后用于某些特定查询。

我该如何告诉剧本哪些评论属于哪个博客文章?

我的想法是将文件的名称或条目的标题或其它东西输入到创建的查询 Im 中。我可能会设法找出如何将文件名也放在 OpenCMS 中—— 搜索大约5分钟(如果有的话) —— 但我不知道我是如何把 OpenCMS 变量 放到文件的 Java 部分, 在那里我设置了实际的查询/ 查询 。

我早些时已经找过了,几周前已经找过了,但后来我设法设法避免了这一点。 虽然我也想不出避免的方法,但我还是希望有人知道如何妥善完成这件事。

如果需要的话,这里是迄今为止实际博客条目的代码, 我将在作者信息下面附上评论功能( 是一个元素) 。

                <cms:contentcheck ifexistsone="Header"><h2><cms:contentshow element="Header" /></h2></cms:contentcheck>
                <p class="BlogEntry">
                <cms:contentcheck ifexistsone="Text"><cms:contentshow element="Text" /></cms:contentcheck>  
                <cms:contentcheck ifexistsone="IntLink"><%@ include file="/system/modules/de.medienkonzepte.uform.templates/elements/internerlink.txt" %></cms:contentcheck>
                </p>
                <cms:contentcheck ifexistsone="Image">
                    <cms:contentloop element="Image">
                        <img style="padding:10px;" src="<cms:link><cms:contentshow element="ImageSrc" /></cms:link>" alt="<cms:contentshow element="Alt_Tag" />" />
                    </cms:contentloop>
                </cms:contentcheck>

            </cms:contentloop>
        </cms:contentcheck>
                 <cms:contentcheck ifexistsone="Content/Text">

        <c:set var="dateString"><cms:contentshow element="Date"/></c:set>
        <% 
         java.util.Date date = new java.util.Date(); 

         date.setTime(Long.parseLong(pageContext.getAttribute("dateString").toString())); 
         pageContext.setAttribute("date", date); 
        %>                  

                <% // Author %>
                <cms:contentcheck ifexistsone="Author"><p class="blogentry_author">Written by: <cms:contentshow element="Author"/> on <fmt:formatDate value="${date}" type="date" pattern="dd.MM.yyyy"/></p></cms:contentcheck>

        </cms:contentcheck> 
    </div> <% // ende innercontent %>
问题回答

一些开发者博客的评论功能

Is the user on the detail page of the blog entry (only this one entry for the entire page), with a comment form at the bottom, as very common, i.e. in Wordpress blogs? Or is it a page with multiple blog entries on it?

如果您在细节页面上, 您可以立即用 Java 代码获取当前文件名 :

CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
String filename = cms.getRequestContext().getUri();

but what I don t know is how I get the OpenCMS variable into my Java part of the file, where I set up the actual query/queries.

<c:set var="filename" scope="request">output your OpenCms variable in here</c:set>

然后您可以通过下列方式访问文件名变量

 request.getAttribute("filename")

您在哪里查询? 在 jsp 或 java 类中正确吗? 但无关紧要, 您可以将请求作为参数传递给它 。 这是做到这一点的方法 :





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签