我想在我的一个软件包中放入一些JavaScript文件,让Struts像他们一样服务 /struts/js/foo.js
Struts为'template'包中的文件执行此操作(这是jQuery插件的文件所在的位置,由struts.ui.templateDir选项保护).但是我想把这些文件放到另一个包中; 如果我重新定义,struts.ui.templateDir那么struts停止工作,因为它无法找到它的模板.
所以现在的问题是:如何判断的Struts中提供文件服务org.foo.some.package.js的/struts/js/whatever.js?
我有一个带有ResourceKey和Caption的List值,这些值都是字符串.资源是资源字典中定义的实际资源的名称.这些ResourceKey图标中的每一个都是Canvas的.
<Data ResourceKey="IconCalendar" Caption="Calendar"/>
<Data ResourceKey="IconEmail" Caption="Email"/>
Run Code Online (Sandbox Code Playgroud)
然后我有一个列表视图,其中有一个带按钮的datatemplate和按钮下方的文本标题.我想要做的是显示资源静态资源作为按钮的内容.
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button Content="{Binding ResourceKey}" Template="{StaticResource RoundButtonControlTemplate}"/>
<TextBlock Grid.Row="1" Margin="0,10,0,0" Text="{Binding Caption}" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
我想我已尝试使用绑定staticresource等进行每个排列.
我对替代方案持开放态度,我知道拥有一个图像并设置source属性可能更容易.
谢谢
如果我在ASP.NET MVC1(或2)Web应用程序中为静态资源请求资源,请说...图像或javascript文件或css文件... .NET框架是否尝试查看如果请求匹配路由列表...并最终找不到它的控制器?
例如.
资源:/Content/Images/Foo.png
此请求是否通过我的路由列表..无法将任何控制器/操作与此请求匹配,然后直接尝试该路径?
我想加载我的静态资源.首先我认为它已经有效,但这只是浏览器缓存的一个技巧.我只按预期加载了html文件,但我没有得到js,css,图像等等.
======
我的StartClass:
@Configuration
@Import({ ServiceConfig.class, WebMvcConfig.class })
@EnableHypermediaSupport(type = HAL)
@EnableAutoConfiguration
public class ApplicationClientMvc {
public static void main(final String[] args) {
SpringApplication.run(ApplicationClientMvc.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
======
WebMvcConfig
@Configuration
@ComponentScan
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Autowired public SpringTemplateEngine templateEngine;
@Bean
public ThymeleafTilesConfigurer tilesConfigurer() {
final ThymeleafTilesConfigurer configurer = new ThymeleafTilesConfigurer();
configurer.setDefinitions("classpath*:/templates/**/views.xml");
return configurer;
}
@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
final ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setViewClass(ThymeleafTilesView.class);
resolver.setTemplateEngine(templateEngine);
resolver.setCharacterEncoding(UTF_8);
return resolver;
}
@Bean
public TilesDialect tilesDialect() {
return new …Run Code Online (Sandbox Code Playgroud) 当网页加载时,我在调试器中收到警告
资源解释为样式表,但使用MIME类型text/plain进行传输.
当浏览器请求js,css,gif和png文件时,我收到上述警告.
知道如何解决此警告
我正在构建一个Spring MVC应用程序,并且frontController servlet映射为"/"拦截所有请求,我将能够从tomcat提供静态内容(.js,.css,.png ...)不是春天.我的app结构是
-webapp/
styles/
images/
WEB-INF/
views/
Run Code Online (Sandbox Code Playgroud)
默认情况下,因为frontController映射到我的应用程序的上下文根,它处理所有请求但不提供任何静态资源.下面是静态资源的mvc配置.
<mvc:resources mapping="/resources/**" location="/"/>
Run Code Online (Sandbox Code Playgroud)
页面的代码是:
<img src="resources/images/logo.png" />
Run Code Online (Sandbox Code Playgroud)
我需要配置Tomcat来提供静态资源而不需要Spring交互.
有什么建议吗?
我正在通过多个 maven 模块开发一个解决方案来处理不同的有界上下文。
多亏了 spring boot,每个模块都公开了自己的 rest api,并且所有这些都托管在一个 maven 模块中,并带有一个由 @SpringBootApplication 注释的类。简化的项目结构如下所示:
parent
|-- pom.xml
|-- ...
|-- host
|-- Application.java
|-- resources
|-- index.html
|-- driver
|-- api
|-- resources
|-- register.html
|-- notify
|-- ...
|-- passenger
|-- ...
Run Code Online (Sandbox Code Playgroud)
在面对复合 UI 时,我尝试使用相同的模式:一个保存布局、静态资源的地方,同时,html 页面属于保存在其 maven 模块中的每个有界上下文。
问题是我在 spring boot doc 中发现,无法从其他 jar 文件中提供静态资源。
是否有任何解决方案可以获得此功能,或者这里是否存在任何架构错误?或者弹簧之外的东西(例如覆盖层)是解决方案吗?
通过此设置,我可以完美地提供静态资源,但是我必须逐个文件地定义允许提供服务的文件。
我当前的用例是目录中的任何内容都/resources/public/应该允许客户端访问。
我已经尝试过 one liner /resources/public/**,但/public/**仍然不允许访问我收到 403 的所有公共资源。因此,在我的 http 配置中,我已经开始定义允许的文件扩展名,但我不喜欢这种方法,因为我的 web 应用程序中有很多不同的扩展名。
我的问题是,如何允许访问所有文件,而/resources/public/不必为每个文件扩展名定义 ant 匹配器,或者我只是小气?
Spring WebSecurityConfigurerAdapter- 根据 jmw5598 的答案进行编辑。
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) {
http
.authorizeRequests()
.authorizeRequests()
.antMatchers(
"/public/**",
"/.svg", "/.ico", "/.eot", "/.woff2",
"/.ttf", "/.woff", "/.html", "/.js",
"/.map", "/*.bundle.*",
"/index.html", "/", "/home", "/dashboard")
.permitAll()
.anyRequest().authenticated();
}
Run Code Online (Sandbox Code Playgroud)
服务网络应用程序的控制器:
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600)
@Controller
public class AngularWebAppController …Run Code Online (Sandbox Code Playgroud) 在使用 .war 输出进行 Web 开发之前,可以选择模块化战争覆盖http://maven.apache.org/plugins/maven-war-plugin/overlays.html
现在Spring Boot采用了jar包,如何做一些共享的web资源呢?
那就是依赖于com.company.shared.web模块,比如说,图像
/com.company.shared.web/src/main/resources/static/images/background-image.png
如何使这个图像可用于在主模块中运行 Spring boot 应用程序?Maven 标准依赖项解析将只使 Java 类可用。
PS 类似的问题,但对于 .war 打包是Spring Boot 和 Maven 战争覆盖并没有解决https://github.com/spring-projects/spring-boot/issues/1030
我的项目树如下所示:
我现在可以访问模板,但无法加载 CSS、图像和 JS 等静态资源。
我有一个common.html片段,在其中声明所有静态资源,例如:
<link rel="stylesheet" th:href="@{/css/app.css}"/>
Run Code Online (Sandbox Code Playgroud)
我包含的标题片段common.html如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:include="fragments/common :: commonFragment" lang="en"></head>
// page body
</html>
Run Code Online (Sandbox Code Playgroud)
default.html布局文件:
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head th:include="fragments/common :: commonFragment" lang="en">
<meta charset="utf-8"/>
<meta name="robots" content="noindex, nofollow"/>
<title>Touch</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="content-dataType" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<link rel="shortcut icon" th:href="@{/static/images/favicon.ico}" type="image/x-icon" />
</head>
<body>
<div th:id="defaultFragment" th:fragment="defaultFragment" class="container">
<div id="header" th:replace="fragments/header :: headerFragment" …Run Code Online (Sandbox Code Playgroud) 我想添加一个已在 XAML 中实例化一次的单个模型对象,并将其添加到两个不同的集合(在 xaml 中)。
以下代码在 Blend 的设计时呈现良好,但在运行时出现以下错误:
对于“
WpfBlog.Models.Tag”类型的“Post1”对象,无法转换为“System.Collections.ObjectModel.ObservableCollection`1[WpfBlog.Models.Tag]”类型。标记文件 'WpfBlog;component/Admin.xaml' 行 XX 位置 YY 中的对象 'WpfBlog.Admin' 处出错。
如果我注释掉“Post1”,我将在“Post2”上收到此错误
无法将元素添加到属性“Tags”,因为如果该属性使用显式集合标记,它只能有一个子元素。标记文件“WpfBlog;component/Admin.xaml”行 AA 位置 BB 中的对象“System.Windows.StaticResourceExtension”处出错。
<Window.Resources>
<model:Tag x:Key="TDD" Name="TDD" ForeColor="Black" BackColor="White" />
<model:Tag x:Key="Agile" Name="Agile" ForeColor="White" BackColor="Black" />
<model:Tag x:Key="Waterfail" Name="Waterfail" ForeColor="Red" BackColor="White" />
</Window.Resources>
<Window.DataContext>
<local:AdminViewModel>
<local:AdminViewModel.AllTags>
<StaticResource ResourceKey="TDD"/>
<StaticResource ResourceKey="Agile"/>
<StaticResource ResourceKey="Waterfail"/>
</local:AdminViewModel.AllTags>
<local:AdminViewModel.Posts>
<local:PostViewModel Title="Post1">
<local:PostViewModel.Tags>
<StaticResource ResourceKey="TDD" />
</local:PostViewModel.Tags>
</local:PostViewModel>
<local:PostViewModel Title="Post2">
<local:PostViewModel.Tags>
<StaticResource ResourceKey="TDD" />
<StaticResource ResourceKey="Agile" />
<StaticResource ResourceKey="Waterfail" />
</local:PostViewModel.Tags> …Run Code Online (Sandbox Code Playgroud) 是否可以在Jar中打包静态资源(如Css,Js或图像)以用于Web应用程序(战争)?
我想将应用程序的各个部分分成模块,但这些不仅依赖于Java类,如控制器或模型,还依赖于视图,模板和媒体.所以我想在Maven模块项目中打包所有这些,并将类复制到类路径和静态文件到应用程序或WEB-INF根目录下的任何目录.
我开发了一个java 1.4 Web应用程序.应用程序部署在jboss(tomcat)上.
假设我的文件夹结构是
mainfolder(contains subfolders and jsp pages)
images(contains all of images files)
headerfiles(header files)
javascript(javascript files)
Run Code Online (Sandbox Code Playgroud)
网站登录页面的网址是
mywebsite.com/mainfolder/login.jsp
Run Code Online (Sandbox Code Playgroud)
如果用户为某些静态资源键入完整的URL
mywebsite.com/mainfolder/images/myimage.jpeg
Run Code Online (Sandbox Code Playgroud)
然后他可以在这个网址上查看图片.
我想阻止用户查看这些资源.我该怎么办?
是否有某种方式来规定我不希望用户看到的文件名模式.在这种情况下,我可以指定要隐藏的*.ssi模式.
static-resource ×13
java ×5
spring-boot ×4
maven ×3
spring ×2
thymeleaf ×2
tomcat ×2
wpf ×2
asp.net-mvc ×1
binding ×1
css ×1
data-binding ×1
jar ×1
jboss ×1
routing ×1
serving ×1
struts2 ×1
xaml ×1