- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
JSP Cookie
Hallo zusammen,
versuche schon die ganze Zeit im FirstSpirit Client 4.2.437.44763 mit untenstehenden Code ein Cookie mit JSP zu erzeugen.
Das funktioniert bis jetzt aber nur, wenn keiner oder nur wenig CMS-Code in der Seite vorhanden ist. Kann es sein, dass es da eine Inkompatibilitรคt gibt oder hat jemand schon mal Erfahrung mit Cookies gemacht?
<form name="formBookmarkLecture2" id="formBookmarkLecture2" method="post" action="">
<input type="checkbox" onclick="document.formBookmarkLecture2.submit()" name="username" class="addToBookmark" value="1">
</form>
<%
String username=request.getParameter("username");
if(username==null) username="";
Cookie cookie = new Cookie ("username",username);
cookie.setMaxAge(365 * 24 * 60 * 60);
response.addCookie(cookie);
%>
<%
String cookieName = "username";
Cookie cookies [] = request.getCookies ();
Cookie myCookie = null;
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++)
{
if (cookies [i].getName().equals (cookieName))
{
myCookie = cookies[i];
break;
}
}
}
%>
<%
if (myCookie == null) {
%>
No Cookie found with the name <%=cookieName%>
<%
} else {
%>
<p>Welcome: <%=myCookie.getValue()%>.
<%
}
%>
Grรผsse,
Sandra Stolle
- Labels:
-
Developers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Noch ein Hinweis, der Code ist in einer Datenbank-Vorlage implementiert. Und wenn in dieser vor dem obigen Code diese Zeilen eingefรผgt werden, kann das Cookie im Browser nicht gesetzt werden:
$CMS_IF(!#row.title.isEmpty || !#row.short_title.isEmpty || !#row.abstract.isEmpty)$
<div class="headContainer grouping">
<div class="textContent">
$CMS_IF(!#row.title.isEmpty)$<h1>$CMS_VALUE(#row.title)$</h1>$CMS_END_IF$
$CMS_IF(!#row.short_title.isEmpty)$<h2>$CMS_VALUE(#row.short_title)$</h2>$CMS_END_IF$
$CMS_IF(!#row.abstract.isEmpty)$<p>$CMS_VALUE(#row.abstract)$</p>$CMS_END_IF$
</div>
</div>
$CMS_END_IF$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Cookies kรถnnen nur gesetzt werden, wenn noch keine Daten an den Browser geschickt wurden. Also entweder die Cookies vor jeglicher HTML-Ausgabe setzen oder den Java PageBuffer entsprechend groร setzen.

