Struts标签不能用于默认操作

时间:2015-02-03 20:37:17

标签: jsp struts2 localization tags

我有 struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />

    <package name="com.alexsimo.examen6" extends="struts-default" namespace="/">

        <default-action-ref name="login-form" />

        <action name="login-form">
            <result>login.jsp</result>
        </action>
        <action name="login" class="com.alexsimo.examen6.LoginAction">
            <result name="success">home.jsp</result>
            <result name="input">login.jsp</result>
        </action>
        <action name="logout" class="com.alexsimo.examen6.LoginAction" method="logout">
            <result>login.jsp</result>
        </action>

    </package>

</struts>

我想实现正常的登录流程。用户输入网站的根目录并获取“登录表单”,他提交,验证(这种情况下我有 LoginAction-validation.xml 文件,名称与登录操作名称完全相同)然后用户被发送到主页,在这种情况下是home.jps。

login.jsp的内容:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!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">
    <link href="<s:url value="/css/style.css"/>" rel="stylesheet" type="text/css" />
    <title><s:property value="%{getText('login.title')}" /></title>
</head>
<body>

    <div id="languages">
        <s:url action="login" id="urlIdiomaES">
            <s:param name="request_locale">es</s:param>
        </s:url>
        <s:url action="login" id="urlIdiomaEN">
            <s:param name="request_locale">en</s:param>
        </s:url>
        <ul>
            <li><s:a href="%{getText('urlIdiomaES')}">Español</s:a></li>
            <li><s:a href="%{getText('urlIdiomaEN')}">English</s:a></li>
        </ul>
    </div>

    <h2><s:property value="%{getText('login.title')}" /></h2>

    <s:if test="errors.size() > 0">
        <div id="lista-errores">
            <label><s:property value="%{getText('login.errors')}" />:</label>
            <s:fielderror />
            <s:actionerror/>
        </div>
    </s:if>

    <s:form action="login" method="post">
        <s:textfield name="username" id="username" label="%{getText('login.username')}" maxLength="30" />
        <s:password name="password" id="password" label="%{getText('login.password')}" maxLength="30" />
        <s:submit key="login.button_title" align="center" />
    </s:form>
</body>
</html>

问题是它似乎没有解释任何struts标签。它给了我简单的HTML:

struts 2 no tags working

任何文件内容都只是要求它。谢谢!

0 个答案:

没有答案