【问题标题】:How to check file existence using Struts 1 tags?如何使用 Struts 1 标签检查文件是否存在?
【发布时间】:2015-02-16 06:48:38
【问题描述】:

我需要检查 html 文件是否存在于某个路径上,如果没有,则需要显示一条消息。

Struts 1中是否有标签定义方便检查文件是否存在?

【问题讨论】:

  • 在控制器 Java 类中这样做比在视图中要好得多。

标签: java struts taglib


【解决方案1】:
//filePath taken from bean variable on struts
boolean fileExists = new java.io.File(getServletContext().getRealPath("/")+java.io.File.separator+filepath).exists();
if(fileExists)
{
%>
<jsp:include page='<%=correct.toString()%>' /> <br />
<%
}
else
{   
%>
<jsp:include page='<%="/html/error/error.html"%>' /> <br />
<%
}
%>

这种策略是有效的。 问这个问题的目的只是为了研究struts是否提供了这样的概念。不幸的是,一些评论家将这个问题降级为否定。真正令人恶心的平台stackoverflow是知识收集。

【讨论】:

  • boolean fileExists = true; fileExists=true; ?那么存在的检查在哪里?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 2021-12-24
  • 2018-03-04
  • 1970-01-01
相关资源
最近更新 更多