JSTL - c:url不使用表单操作

时间:2014-03-06 20:51:36

标签: jsp spring-mvc jstl

我遇到使用tag在JSP中设置表单路径的问题。我也在表格标签之外,它工作正常。但是它似乎在spring form标签内部不起作用。我做错了什么或者它在其他JSTL标签内不起作用?提前谢谢!

这是表单标签之外的版本打印正确的版本。

/ searchtool /用户/添加

这是表单操作设置为:

/ searchtool /用户/%3CC:URL%20value = '/用户/添加' %20 /%3E

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<div class="container">
    <div class="row">
        <div class="col-xs-12 col-sm-8 col-md-6">
            <h3>User - Add</h3>
            <br>

            <spring:hasBindErrors name="user.*">
                <div class="alert alert-danger">
                    <sf:errors path="firstName"></sf:errors>
                    <sf:errors path="lastName"></sf:errors>
                    <sf:errors path="email"></sf:errors>
                    <sf:errors path="userName"></sf:errors>
                    <sf:errors path="password"></sf:errors>
                </div>
            </spring:hasBindErrors>

            <sf:form commandName="user" method="post" action="<c:url value='/user/add' />"> <c:url value='/user/add' />
                <div class="form-group">
                    <label for="first-name">First Name</label>
                    <sf:input path="firstName" id="first-name" class="form-control" placeholder="First Name" />
                </div>
                <div class="form-group">
                    <label for="last-name">Last Name</label>
                    <sf:input path="lastName" id="last-name" class="form-control" placeholder="Last Name" />
                </div>
                <div class="form-group">
                    <label for="email">Email</label>
                    <sf:input path="email" id="email" class="form-control" placeholder="Email" />
                </div>
                <div class="form-group">
                    <label for="user-name">Username</label>
                    <sf:input path="userName" id="user-name" class="form-control" placeholder="Username" />
                </div>
                <div class="form-group">
                    <label for="password">Password</label>
                    <sf:password path="password" id="password" class="form-control" placeholder="" />
                </div>
                <div class="form-group">
                    <label for="confirm-password">Confirm Password</label>
                    <input type="password" id="confirm-password" class="form-control" placeholder="" />
                </div>
                <button type="submit" class="btn btn-default">Save</button>
                <button type="button" class="btn btn-default">Cancel</button>
            </sf:form>
        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:21)

您无法在代码中使用代码。因此,请按以下方式分隔您的代码:

<c:url var="post_url"  value="/user/add" />
<sf:form commandName="user" method="post" action="${post_url}"> 

答案 1 :(得分:0)

即使Santhosh Joshi回答是首选方式,只是告知替代方法

<sf:form commandName="user" method="post" action="${pageContext.request.contextPath}/user/add">