Problems in JSP implementation using Struts2

Asked

Viewed 106 times

1

After executing the following jsp:

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hey!</title>
</head>
<body>

    <c:choose>
        <c:when test="${session.loggedin == true}">
            <p>Welcome, ${session.username}. Say HEY to someone.</p>
        </c:when>
        <c:otherwise>
            <p>Welcome, anonymous user. Say HEY to someone.</p>
        </c:otherwise>
    </c:choose>

    <c:forEach items="${heyBean.allUsers}" var="user">
        <a href="
            <s:url action="say" method="post">
                <s:param name="username" value="session.username" />
                <s:param name="myFriend" value="${user}"/>
            </s:url>
            "><c:out value="${user}"/><br>
        </a>
    </c:forEach>

    <p><a href="<s:url action="index" />">Start</a></p>

</body>
</html>

I have the following bug: According to TLD or attribute Directive in tag file, attribute value does not Accept any Expressions

  • http://meta.pt.stackoverflow.com/questions/297/quando-se-deve-colocar-o-nome-da-linguagem-no-t%c3%adtulo/1911#1911

1 answer

-1

In Struts tags, expressions are delimited by a percentage: %{...}. Different from JSTL tags that use the dollar sign: ${...}.

Try to do this in your example:

<s:param name="myFriend" value="%{user}"/>
  • <s:param name="myFriend" value="${user}"/>, this line looks like this and this line: <c:out value="${user}"/><br> looks like this. But the following errors occur when compiling: The first Textprovider in the Valuestack (com.opensymphony.xwork2.Actionsupport) could not locate the message Resource with key 'Username:'

  • @Andrélizardo It’s the other way around, the Struts tags are the ones that start with s: and should have the percentage. Tags that start with c: are from JSTL and can use the cipher. About the other error you got, it has nothing to do with the code posted in this question. It must have a label somewhere else and missing entry in the internationalization file (.properties).

  • 2

    Does anyone have any idea why downvote? There’s something wrong with the answer?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.