powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / SortedSet и JSTL
7 сообщений из 7, страница 1 из 1
SortedSet и JSTL
    #33803849
maxq
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Передаю на jsp страничку параметр items типа SortedSet
И на jsp страничке мне нужно взять его первый елемент.
Я пытаюсь его достать с помощью
Код: plaintext
1.
<c:set var="item" value="${items.first}"/>
или
Код: plaintext
1.
<c:set var="item" value="${items.[0]}"/>

но происходит ошибка :
Код: plaintext
1.
javax.servlet.jsp.JspException: An error occurred  while  evaluating custom action attribute "value" with value "${items.first}": Unable to find a value  for  "first" in object of  class  "org.hibernate.collection.PersistentSortedSet" using operator "." ( null )
или
Код: plaintext
1.
javax.servlet.jsp.JspException: An error occurred  while  evaluating custom action attribute "value" with value "${items[0]}": Unable to find a value  for  "0" in object of  class  "org.hibernate.collection.PersistentSortedSet" using operator "[]" ( null )

Как я могу взять первый елемент SortedSet ???
Может кто-то уже сталкивался с этой задачей, подскажите.
...
Рейтинг: 0 / 0
SortedSet и JSTL
    #33804636
ТимоН
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
автормне нужно взять его первый елемент.
почему тогда <c:set .../>

Код: plaintext
1.
2.
3.
4.
<%-- Save data in scoped variables --%>
    <c:set var="name1" value="value1" scope="page" />
    <c:set var="com_mycompany_name2" value="value2" scope="request" />
    <c:set var="com_mycompany_name3" value="value3" scope="session" />
    <c:set var="com_mycompany_name4" value="value4" scope="application" />

Data is saved using a mechanism called scoped variables. A scoped variable has a name, which is of type String and a value, which is of type Object. For non-page scoped variables, it is recommended that the name use the reverse domain name convention (e.g., prefixed with com_mycompany) to minimize unexpected collisions when integrating with third party modules.

В вашем случае:
Код: plaintext
1.
2.
3.
4.
    <%-- Show the saved values without a specific scope --%>
    <c:out value='${name1}' />
    <c:out value='${com_mycompany_name2}' />
    <c:out value='${com_mycompany_name3}' />
    <c:out value='${com_mycompany_name4}' />
...
Рейтинг: 0 / 0
SortedSet и JSTL
    #33805062
maxq
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Спасибо за инфу, но чесно говоря я не нашел
в ней ответа на мой вопрос :(
...
Рейтинг: 0 / 0
SortedSet и JSTL
    #33805073
ТимоН
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
несилен в JSTL, что-то в этом роде
Код: plaintext
<c:out value='${items.first}' />
...
Рейтинг: 0 / 0
SortedSet и JSTL
    #33805114
maxq
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
ТимоНнесилен в JSTL, что-то в этом роде
Код: plaintext
<c:out value='${items.first}' />


Пробывал, но постоянно получаю ошибку,
которую описал раньше.
...
Рейтинг: 0 / 0
SortedSet и JSTL
    #33805168
ТимоН
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Neglecting to Store Variables in a Scope

Although it's not recommended for production code, it is not uncommon for developers to create some temporary objects in a scriptlet that act as placeholders for data that will eventually come from another source; for example, you can create a hash map in a scriptlet that you can subsequently access with an EL expression, like this:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
<%
   java.util.HashMap map =  new  java.util.HashMap();
   map.put("key One", "value One");
   map.put("key Two", "value Two");
   map.put("key Three", "value Three");
   map.put("key Four", "value Four");
   map.put("key Five", "value Five");
%>

<c:out value='${map["key One"]}'/>

You may think that the preceding code fragment will display the value of the first entry added to the map, but in actuality, it will display nothing at all because the map created in the scriptlet was never stored in one of the JSP scopes.

Once the map is placed in one of the JSP scopes, it can be accessed with an EL expression. Here is the corrected code fragment:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
<%
   java.util.HashMap map =  new  java.util.HashMap();
   map.put("key One", "value One");
   map.put("key Two", "value Two");
   map.put("key Three", "value Three");
   map.put("key Four", "value Four");
   map.put("key Five", "value Five");

   pageContext.setAttribute("map", map);
%>

<c:out value='${map["key One"]}'/>

You can iterate over the items stored in the map created above like this:

Код: plaintext
1.
2.
<c:forEach var='item' items='${map}'>
   <c:out value='Key=${item.key}, Value=${item.value}'/>
</c:forEach>

http://www.phptr.com/articles/article.asp?p=30946&seqNum=10&rl=1
...
Рейтинг: 0 / 0
SortedSet и JSTL
    #33805178
ТимоН
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Writing Output to the JspWriter

There are four general-purpose tags. The <c:out> tag is probably the tag that you will see the most. It is used to output to the current JspWriter. This is similar to using the JSP expression <%=scripting language expression %> to write dynamic data to the client.

The value to be written to the JspWriter is specified as a value attribute. You can use expressions in the value attribute. This allows for the resulting evaluation to be sent to the JspWriter. The <c:out> tag can perform XML character-entity encoding for <, >, &, ", and '. This means that a < will be automatically encoded to <. The book includes a table of the XML entity values that are used for encoding the characters. Therefore, it's possible also to use this encoding capability to encode any HTML, such as <br>, so that the angle brackets appear correctly. This capability is controlled by the escapeXml attribute. It defaults to true.

It should be obvious that:

The title of the book you just purchased is
<c:out value="${sessionScope.bookInfo.title}">

is much easier to read (and write) than:

<%@page import="com.mk.jstl.bookInfo"%>
<%BookInfo bookInfo =(BookInfo)session.getAttribute"
("bookInfo");
%>
The title of the book you just purchased is
<%=bookInfo.getTitle()%>

In another example, we might want to output some data values that have been stored in a scoped variable called myData. The value of myData is "<b>I love to ride my bicycle</b>". There are HTML tags included in the string that we want to make sure are rendered correctly, with the string bolded. To ensure that the data is displayed to the user correctly, we would use:

<c:out value=${myData}escapeXml="false"/>

With escapeXml set to false, our users see the correct display with the text bolded.

Otherwise, they just see the characters <b> displayed with the text, as shown in Figure 1.

The two displays are shown as they would appear if you were to view the source of the resulting file in your browser. The first output is using the default value of escapeXml, while the second output shows the result of using escapeXml set to false. With escapeXml defaulting to true:

<b>I love to ride my bicycle</b>

With escapeXml set to false:

<b>I love to ride my bicycle</b>
...
Рейтинг: 0 / 0
7 сообщений из 7, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / SortedSet и JSTL
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]