JSP 页面未填充与关联的 formBean 属性
<html:select property="fileLocation">
<%
ArrayList uploadLocationLookUp = null;
uploadLocationLookUp = (ArrayList) request.getSession().getAttribute("uploadLocation");
if (uploadLocationLookUp.size() != 0) {
for (int i = 0; i < uploadLocationLookUp.size(); i++) {
LookUpBean lookUpBeanItems = (LookUpBean) uploadLocationLookUp.get(i);
%>
<html:option value="<%=lookUpBeanItems.getLookUpCode()%>">
<%= lookUpBeanItems.getLookUpCode() %>
</html:option>
<% }} %>
</html:select>
我使用 LookUpBean 填充 select 标记中的选项,该标记与具有 fileLocation 属性的 formBean 关联。
虽然所有其他属性都填充了 formBean 中的属性,但这个属性却不是。我还尝试在我的操作类中使用 request.getParameter("fileLocation") 来获取它,但它不起作用。
有人能仔细观察这段代码并指出任何可能被遗漏的愚蠢错误吗?我可能遇到其他领域/问题吗?如果能快速回复,我们将不胜感激。谢谢
它成功了:) 但不知道为什么:(
我所做的只是重构我的代码并重新排列表单上的输入元素。一旦我将流氓
放在我的一段 java 代码之后jsp,它就像一个魅力。任何人都可以指出我做的错误以及为什么在我重新排列我的表单元素后它会起作用吗?
<html:select property="fileLocation">
<%
ArrayList uploadLocationLookUp = null;
uploadLocationLookUp = (ArrayList) request.getSession().getAttribute("uploadLocation");
if (uploadLocationLookUp.size() != 0) {
for (int i = 0; i < uploadLocationLookUp.size(); i++) {
LookUpBean lookUpBeanItems = (LookUpBean) uploadLocationLookUp.get(i);
%>
<html:option value="<%=lookUpBeanItems.getLookUpCode()%>">
<%= lookUpBeanItems.getLookUpCode() %>
</html:option>
<% }} %>
</html:select>
I'm using the LookUpBean to populate the options in the select tag which is associated with a formBean with property fileLocation.
While all other properties are populating property in the formBean this one is not. I also tried getting to it using request.getParameter("fileLocation") in my action class but it just wont work.
Can anyone eyeball this chunk of code and point out any silly mistake that might have been missed? Are there other areas/issues that I might have run into? A quick response would be much appriciated. Thanks
It worked :)
Don't know why though :(
All I did was refactor my code and rearranged the input elements on my form. Once I placed the rogue <html:select>
after a piece of java code on my jsp, it worked like a charm. Can anyone give pointers to something wrong that I did and why it worked after I rearranged my form elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
fileLocation
和lookUpCode
属性都是字符串,我没有发现这段代码有任何明显的错误。一个提示,您应该能够使用 消除 scriptlet 代码html:选项 标签:
I don't see anything obviously wrong with this code, provided that both the
fileLocation
andlookUpCode
properties are Strings.One tip, you should be able to eliminate the scriptlet code by using the html:options tag: