我正在尝试创建一个表单来编辑现有的数据库行.我正在使用Spring MVC表单标记将html自动绑定到表单后备对象.该行与另一个表有多对多的关系,我试图使用以下形式表示多个选择框:select tag;
<form:select path="rules">
<form:options items="${bundle.rules}" itemValue="name" itemLabel="name"/>
</form:select>
Run Code Online (Sandbox Code Playgroud)
我正在使用Hibernate进行持久化,因此该关系表示为Bundle pojo中的HashSet.
private Set<Rule> rules = new HashSet<Rule>(0);
Run Code Online (Sandbox Code Playgroud)
如果没有页面上的选择框,对象将正确更新到数据库,但是使用选择框,对象将不会更新到数据库,并且我在log4j日志中收到此错误,请注意此错误不会导致异常,它只在日志中可见;
DEBUG org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:256) - Data binding errors: 1
Run Code Online (Sandbox Code Playgroud)
无论我取消选择框内的项目,都会发生这种情况,整个表单拒绝正确提交.谁能帮我?
我知道如何将集合属性绑定到Spring MVC中的表单,这与此问题类似,遗憾的是,没有任何建议对我的问题有用.
大家好,我们正在尝试为我们的Web应用程序实现一些功能,我们正在使用Spring Framework v4.1.1和Spring Security v3.1.7进行Web应用程序.我们正在使用自定义身份验证提供程序进行身份验证过程,一切正常,但是当我们尝试使用Spring Security中的JSP标记隐藏页面中特定角色的某些内容时,它不起作用.
这是我们的security-conf.xml
<http pattern="/resources/**" security="none" />
<http use-expressions="true">
<form-login login-page="/login" authentication-failure-url="/loginerroneo"
default-target-url="/seleccionar-empresa" always-use-default-target="true"/>
<logout logout-success-url="/login" logout-url="/salir"/>
<session-management invalid-session-url="/login" />
</http>
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService">
</authentication-provider>
</authentication-manager>
<global-method-security pre-post-annotations="enabled"/>
<beans:bean id="userDetailsService" class="com.grupo.seguridad.acceso.service.impl.UserDetailsServiceAdapater"/>
Run Code Online (Sandbox Code Playgroud)
当我们<sec:authentication property="principal.authorities"/> 在页面中使用此标记时,我们得到了[VENDEDOR,ADMINISTRADOR]这是正确的.
但是当我们尝试使用标记隐藏页面的某些内容时:
<sec:authorize access="hasRole('ADMINISTRADOR')">
<button class="btn btn-small btnGuardar" href="#dlgGuardar" data-toggle="modal">
<i class="icon-hdd"></i> <strong>Una Opcion</strong>
</button>
</sec:authorize>
Run Code Online (Sandbox Code Playgroud)
这是行不通的.
我们不知道我们做错了什么.谢谢你的帮助,最诚挚的问候,
我正在使用Spring,但这个问题适用于所有JSP控制器类型的设计.
JSP页面引用由相应控制器填充的数据(使用标记).我的问题是,在JSP或控制器中执行格式化的适当位置在哪里?
到目前为止,我一直在通过在控制器中格式化数据来准备数据.
public class ViewPersonController extends org.springframework.web.servlet.mvc.AbstractController
{
private static final Format MY_DATE_FORMAT = new SimpleDateFormat(...);
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
{
Person person = get person from backing service layer or database
Map properties = new HashMap();
// No formatting required, name is a String
properties.put("name", person.getName());
// getBirthDate() returns Date and is formatted by a Format
properties.put("birthDate", MY_DATE_FORMAT.format(person.getBirthDate()));
// latitude and longitude are separate fields in Person, but in the UI it's one field
properties.put("location", person.getLatitude() …Run Code Online (Sandbox Code Playgroud) How do you extend an existing JSP custom tag?
As you know, a custom tag consists of two parts, an implementation class and a TLD file. I can extend the parent custom tag's class, but how do you "extend" its TLD file? One obvious solution is to cut and paste it and then add my stuff, but I wonder if there's a more elegant solution like the way you extend a tiles definition in Apache Tiles.
Thanks.
在工作中,一些开发人员正在将.tag文件更改为用Java编写的标记.原因是表现.他们表示,在比较.tag文件和用Java编写的文件时,性能提高了十倍.证据是经验性的.
我试图找到一些事实数据来支持这一点,但在网上找不到任何性能比较.我确实找到了谈论标签池以及如何提高性能的文档,但我找不到比较这两者的东西.
有没有办法将任意元素的css类绑定到模型绑定状态?
<form:form method="post" commandName="authForm" action="authenticate">
<div id="login-error" class="control-group">
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
<div class="control-group">
<label>Password</label>
<form:input path="password" />
<span class="help-inline"><form:errors path="password" /></span>
</div>
<input type="submit" />
</form:form>
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我需要管理login-error类,以便control-group在没有错误时和control-group error有(第二个相同的想法control-group).
这里有什么常见的解决方案?
更新
这是我没有绑定错误时所需要的:
<div class="control-group"> <!-- !!!!!!!!!!!! -->
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
Run Code Online (Sandbox Code Playgroud)
这是绑定错误时我需要的:
<div class="control-group error"> <!-- !!!!!!!!!!!! -->
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
Run Code Online (Sandbox Code Playgroud)
寻找解决方案.
我想打开一个jsp页面而不访问我的servlete代码.即我既不必在我的jsp代码中输入我的url(action ="url"),也不必访问我的Servlete代码.
<form id="main" method="post" name="main" action="dpRegPost" onsubmit="return validate();">
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我吗?
如果使用者关闭浏览器窗口,我试图清除HttpSession。我不知道该怎么做,请帮助我
感谢和问候Chakri
我有一个像var =的值P+q+EvhE951eg/I5nz1vi/w2YpJdH+v/vSPaQNg/I=
我通过这个参数url一样
http://localhost/proj/home.jsp?var=P+q+EvhE951eg/I5nz1vi/w2YpJdH+v/vSPaQNg/I=
现在在home.jsp中我想使用var的这个值.但是当我这样做时
String var=request.getParameter("var"); var获取值
"P q EvhE951eg/I5nz1vi/w2YpJdH v/vSPaQNg/I="注意它替换+为space.
所以任何人都可以帮我解决这个问题.
我在JSP标记文件中引用静态内部类时遇到问题.我正在使用Glassfish Jersey和Jetty 6.1.X. 我正在使用JSP 2.0和标记文件,我没有任何TagHandler类或任何.tld文件.我的web.xml也不包含任何有关JSP或标记文件的具体内容.
我把问题分解成最小的可重复性:
这是我正在使用的类的结构:
package test;
public class OuterClass {
public static class InnerClass {
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的.tag文件的完整内容:
<%@ attribute name="inner" required="true" type="test.OuterClass.InnerClass" %>
<h1>${inner}</h1>
Run Code Online (Sandbox Code Playgroud)
(标记文件在IntelliJ中显示错误):

我在我的父jsp中使用此标记,如下所示:
<%@taglib tagdir="/WEB-INF/tags" prefix="test" %>
<test:test inner="${inner}"/>
Run Code Online (Sandbox Code Playgroud)
尝试以这种方式使用它时得到的例外是:
org.apache.jasper.JasperException: /WEB-INF/jsp/test.jsp(54,4)
Unknown attribute type (test.OuterClass.InnerClass) for attribute inner
Run Code Online (Sandbox Code Playgroud)
如果我更改类型以使用二进制表示法(OuterClass $ InnerClass),我会收到此错误:
The nested type test.OuterClass$InnerClass cannot be referenced using its binary name
Run Code Online (Sandbox Code Playgroud)
我已经搜索了Google,并发现其他人遇到了同样的问题,但所有这些似乎都已经解决了几年前对Jasper的修复.
https://issues.apache.org/bugzilla/show_bug.cgi?id=41824 https://issues.apache.org/bugzilla/show_bug.cgi?id=35351
我通过将类拆分为许多顶级类来绕过问题,但我的用例中的嵌套类必然属于顶级类,不应在此之外使用,因此更改设计应该是错误的我在这里找到的限制.
如果有一种方法可以在标记属性中正确使用静态嵌套类,那么这将是理想的解决方案.