小编Bri*_*ler的帖子

我应该如何初始化类freemarker.template.Configuration?

试图遵循这个Java教程.

大约63页,您被告知如何创建表单("New.jsp")来提交新事件.

当我尝试访问该页面时,出现以下错误:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Filter execution threw an exception
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause

java.lang.NoClassDefFoundError: Could not initialize class freemarker.template.Configuration
    org.apache.struts2.views.freemarker.FreemarkerManager.createConfiguration(FreemarkerManager.java:294)
    org.apache.struts2.views.freemarker.FreemarkerManager.init(FreemarkerManager.java:255)
    org.apache.struts2.views.freemarker.FreemarkerManager.getConfiguration(FreemarkerManager.java:238)
    org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:734)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:506)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.

Apache Tomcat/6.0.29
Run Code Online (Sandbox Code Playgroud)

我在D:\ education\java.metadata.plugins\org.eclipse.wst.server.core\tmp1\logs\localhost_access_log.2010-09-26.txt找到了这个日志

127.0.0.1 - …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat freemarker struts2

3
推荐指数
1
解决办法
1万
查看次数

是否可以拥有 Azure Key Vault 的本地实例?

我目前正在开发一个 C# 解决方案,它将集成 Azure Key Vault。

如果互联网出现故障(我在柏林工作,所以并非完全不可能),或者如果我想在调试解决方案时排除网络连接问题,有没有办法设置本地实例?

c# localhost local azure azure-keyvault

3
推荐指数
1
解决办法
3701
查看次数

在 C# 中,使用“using”会导致错误,是否有比不使用“using”更好的做法?

我有以下方法:

    [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "If we dispose of the csvWriter, it won't be available to write.")]
    public static MemoryStream CreateCsvStream(IEnumerable<object> records)
    {
        MemoryStream memoryStream = new();
        StreamWriter streamWriter = new(memoryStream);
        CsvWriter csvWriter = new(streamWriter, CultureInfo.InvariantCulture);
        csvWriter.Context.TypeConverterCache.AddConverter<bool>(new CollendaBooleanConverter());
        csvWriter.Context.TypeConverterCache.AddConverter<bool?>(new CollendaBooleanConverter());
        csvWriter.Context.TypeConverterCache.AddConverter<DateOnly>(new CollendaDateOnlyConverter());
        csvWriter.Context.TypeConverterCache.AddConverter<DateOnly?>(new CollendaDateOnlyConverter());
        csvWriter.Context.TypeConverterCache.AddConverter<decimal>(new CollendaDecimalConverter());
        csvWriter.Context.TypeConverterCache.AddConverter<decimal?>(new CollendaDecimalConverter());
        csvWriter.WriteRecords(records);
        streamWriter.Flush();
        return memoryStream;
    }
Run Code Online (Sandbox Code Playgroud)

这是可行的,但正如 中所暗示的SuppressMessage,如果我使用usingso MemoryStreamStreamWriter和/或CsvWriter,当我稍后执行以下代码时,它们将被释放:

    private void Upload(MemoryStream memoryStream)
    {
        _sftpClient.Connect();
        _ = memoryStream.Seek(0, SeekOrigin.Begin);

        string …
Run Code Online (Sandbox Code Playgroud)

c# memorystream using streamwriter csvhelper

3
推荐指数
2
解决办法
338
查看次数

在 C# 中,如何仅在没有类属性的情况下为类属性生成值?

我有以下带有属性的C#Id,我想使用 GUID 设置该属性,如果消费者调用尚未设置此值的 myClass.Id 实例的值,则返回该属性,否则保留并返回现有价值。

public class IdentifiableClass{
   public string Id {
          get { 
                if (this.Id == null) {
                    this.Id = Guid.NewGuid().ToString();
                    Console.WriteLine("########## Id : " + this.Id );
                }
                return this.Id;
            }
            set => this.Id = value;
   }
}
Run Code Online (Sandbox Code Playgroud)

C#中,这样做不是工作,而是我得到一个计算器(不是这个网站,很明显)。最好的猜测是,在同一属性的 getter 中调用 this.Id 似乎会导致循环逻辑。

Salesforce Apex 中,使用类似的代码,它确实按照我的预期工作,将 this.Id 的值评估为 null,将值分配给新的 Guid,显示值,然后返回值:

public class IdentifiableClass {
   public string Id {
          get { …
Run Code Online (Sandbox Code Playgroud)

c# getter guid accessor conditional-statements

2
推荐指数
1
解决办法
337
查看次数

在 C# 中,如何使用 `TryAsync` 的实例?

我有以下方法:

private async Task<(bool, string)> Relay(
        WorkflowTask workflowTask,
        MontageUploadConfig montageData,
        File sourceFile,
        CancellationToken cancellationToken
    )
{
    try
    {
        byte[] fileContent = await _httpClient.GetByteArrayAsync(sourceFile.Url, cancellationToken);
        await _attachmentController.TryUploadAttachment(montageData.EventId, fileContent, sourceFile.Name);
        return (true, null);
    }
    catch (Exception exception)
    {
        _logger.LogError(exception, $"File cannot be uploaded: {sourceFile.Name}", workflowTask);
        return (false, exception.ToString());
    }
}
Run Code Online (Sandbox Code Playgroud)

我想重构它以使用TryAsyncfrom LanguageExt.Core(或其他一些功能Try类型)。

我已成功将上述方法重构为:

private TryAsync<bool> Relay(
    MontageUploadConfig montageData,
    File sourceFile,
    CancellationToken cancellationToken
) => new(async () =>
{
    byte[] fileContent = await _httpClient.GetByteArrayAsync(sourceFile.Url, cancellationToken);
    return await _attachmentController.TryUploadAttachment(montageData.EventId, …
Run Code Online (Sandbox Code Playgroud)

c# language-ext

2
推荐指数
1
解决办法
1782
查看次数

如何以小写形式显示枚举?

我有一个枚举:

pub enum BoxColour {
    Red,
    Blue,
}
Run Code Online (Sandbox Code Playgroud)

我不仅希望将此值作为 string 获取,而且还希望将该值转换为小写。

这有效:

impl Display for BoxColour {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.write_str(match self {
            BoxColour::Red => "red",
            BoxColour::Blue => "blue",
        })?;
        Ok(())
    }
}
Run Code Online (Sandbox Code Playgroud)

当颜色列表增加时,该列表需要更新。

如果我使用write!宏,似乎不可能操纵结果,因为write!返回一个实例()而不是一个String

impl Display for BoxColour {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        write!(formatter, "{:?}", self)
    }
}
Run Code Online (Sandbox Code Playgroud)

这表明这是通过副作用起作用的,也许我们可以在内存中破解该值的相同位置,但即使这是可能的,也可能不是一个好主意......

enums lowercase rust display write

1
推荐指数
2
解决办法
81
查看次数

如何使用<fmt:setLocale>为JSP设置语言环境?

我正在尝试在JSP中设置本地.

我以为我能做的事情如下:

<fmt:setLocale value="${param['local']}" scope="session"/>
Run Code Online (Sandbox Code Playgroud)

关于这个主题的Java自己的页面似乎说得非常多.

但是,当我去执行它时,我得到:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /pages/ResourceBundlesJSTL.jsp(11,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
 org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
 org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
 org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1232)
 org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:868)
 org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
 org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
 org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
 org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
 org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
 org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
 org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1787)
 org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:211)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:360)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause …
Run Code Online (Sandbox Code Playgroud)

jsp locale jstl setlocale

0
推荐指数
1
解决办法
5671
查看次数