JSTL-c:url无法与表单操作一起使用 [英] JSTL - c:url not working with form action

查看:63
本文介绍了JSTL-c:url无法与表单操作一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用标签在JSP中设置表单的路径时遇到问题.我也有它在表单标签之外,并且效果很好.但是,它似乎在spring form标记内不起作用.我是在做错什么,还是在其他JSTL标签中不起作用?预先感谢!

I am having an issue with using tag to set the path of a form in my JSP. I have it outside the form tag as well and that works fine. However it doesn't seem to work inside the spring form tag. Am I doing something wrong or does it not work inside other JSTL tags? Thanks in advance!

这是在表单标签之外打印的版本,这是正确的.

This is what the version outside the form tags prints which is correct.

/searchtool/user/add

/searchtool/user/add

这是表单操作设置为的内容:

This is what the form action is set to:

/searchtool/user/%3Cc:url%20value ='/user/add'%20/%3E

/searchtool/user/%3Cc:url%20value='/user/add'%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>

推荐答案

您不能在标签内使用标签.因此,只需按以下步骤分隔标签即可:

You can't use a tag inside a tag. So just separate your tags as follows:

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

这篇关于JSTL-c:url无法与表单操作一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆