小编Bet*_*sta的帖子

为什么表单提交会打开新窗口/标签?

我发现了很多问题"如何在新窗口中打开表单结果",但我面临着相反的问题.

我有形式:

<form:form method="post" commandName="search">
    ...
    <input type="submit" value="Search" />
</form>
Run Code Online (Sandbox Code Playgroud)

然后我有控制器与处理方法

@RequestMapping(value = "/search.form", method = RequestMethod.POST)
public String submit( @Valid final SearchObject searchObject, final BindingResult bindingResult ) {
    if ( bindingResult.hasErrors() ) return "forms/search";
    return "redirect:/A/result.form";
}
Run Code Online (Sandbox Code Playgroud)

一切正常,除了在新窗口/选项卡中打开结果的事实.

我找到并正在解决的解决方案是添加目标属性:

<form:form method="post" commandName="search" target="_self">
Run Code Online (Sandbox Code Playgroud)

但是_self默认的AFAIK.

我想知道为什么会这样.

我检查生成的HTML,在我看来好吧:

<form id="search" action="/myApp/A/search.form" method="post">
Run Code Online (Sandbox Code Playgroud)

编辑添加的标题

Content-Language    en-US
Content-Length  0
Date    Thu, 22 Mar 2012 16:29:13 GMT
Location    http://localhost:8080/myApp/A/result.form
Server  Apache-Coyote/1.1
Request Headersview source
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/ *;q=0.8
Accept-Encoding …
Run Code Online (Sandbox Code Playgroud)

html java forms spring spring-mvc

9
推荐指数
1
解决办法
5505
查看次数

Java中TreeSet部分视图的size()复杂度是多少

我想知道size()TreeSet的部分视图的时间复杂度是多少.

假设我正在添加随机数来设置(我不关心重复):

    final TreeSet<Integer> tree = new TreeSet<Integer>();
    final Random r = new Random();
    final int N = 1000;
    for ( int i = 0; i < N; i++ ) {
        tree.add( r.nextInt() );
    }
Run Code Online (Sandbox Code Playgroud)

现在我正在考虑size()调用的复杂性:

    final int M = 100;
    for ( int i = 0; i < M; i++ ) {
        final int f = r.nextInt();
        final int t = r.nextInt();
        System.out.println( tree.headSet( t ).size() );
        System.out.println( tree.tailSet( f ).size() );
        if ( f …
Run Code Online (Sandbox Code Playgroud)

java complexity-theory treeset

9
推荐指数
1
解决办法
2005
查看次数

不相容的魔法值0

我在STS中开发java maven项目(基于Eclipse Juno 3.8.2),我收到以下错误:

java.lang.ClassFormatError:类文件中不兼容的魔术值0 org/eclipse/jdt/internal/junit4/runner/JUnit4TestReference

我认为它与混合Java版本有关,但我无法解决它,可能我错过了一些东西.

完整的堆栈跟踪是:

java.lang.ClassFormatError: Incompatible magic value 0 in class file org/eclipse/jdt/internal/junit4/runner/JUnit4TestReference
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at …
Run Code Online (Sandbox Code Playgroud)

java maven

9
推荐指数
1
解决办法
9105
查看次数

如何使用keytool使用SAN创建CSR

我想问一下是否可以创建包含SAN记录的CSR.

我创建了密钥库

keytool -genkeypair -keyalg RSA -keysize 2048 -alias testAlias -ext SAN=dns:test.example.com -keystore test.jks -storetype JKS -dname "CN=test"
Run Code Online (Sandbox Code Playgroud)

我可以使用keytool检查SAN是否在密钥库中

keytool -list -v -keystore test.jks
Run Code Online (Sandbox Code Playgroud)

和输出的相关部分是

#1: ObjectId: 2.5.29.17 Criticality=false
SubjectAlternativeName [
  DNSName: test.example.com
]
Run Code Online (Sandbox Code Playgroud)

然后我使用keytool创建了CSR:

keytool -certreq -file test.csr -keystore test.jks -alias testAlias
Run Code Online (Sandbox Code Playgroud)

但在CSR中有关于缺少SAN的信息.

如何检查:

keytool -printcertreq -file test.csr -v
Run Code Online (Sandbox Code Playgroud)

正确地应该有类似的东西

Extension Request:

#1: ObjectId: 2.5.29.17 Criticality=false
SubjectAlternativeName [
  DNSName: test.example.com
]
Run Code Online (Sandbox Code Playgroud)

我错过了一些选择certreq吗?

certificate keytool

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

Spring Wire一个静态类

我处理遗留代码库,其中未在春天有线了一类需要获得一类在春季接线.我希望创建一个在启动时连接的工厂类,然后我可以调用getInstance()方法来获取有线对象.最好的方法是什么?

例:

public class LegacyA {
    public void doSomething() {
        ...
        Foo foo = FooFactory.getInstance();
        ...
    }
}

public class FooFactory {
    private static Foo foo;

    public static Foo getInstance() {
        if (foo == null) throw new IllegalStateException();
        return foo;
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要在启动时连接FooFactory,以便LegacyA可以简单地调用getInstance(),以便它返回一个Foo实例(它也是在应用程序上下文中定义的bean).

<bean id="legacyA" class="LegacyA"/>

<bean id="foo" class="Foo"/>

<!-- I need this bean to be injected with foo so that the FooFactory can return a foo -->
<bean id="fooFactory" class="FooFactory"/>
Run Code Online (Sandbox Code Playgroud)

编辑:我不得不重新修改我的例子,因为我在自己的头脑中有点困惑...

java spring

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

在Maven中创建依赖关系组以供重用 - 包括"提供的"依赖关系

我是Maven的新手,正在建立我的第一个maven项目.我还以一些pom的形式创建了一些maven资产,这些资源可以在任何未来的项目中继承或用作依赖项.我想将依赖项组合在一起,并能够根据需要有选择地将它们添加到项目中.

我读了这篇关于pom最佳实践的文章.我喜欢将相关依赖项组合到poms中然后根据需要将pom作为依赖项添加到项目中的想法.这种方法适用于编译范围的依赖项.但是,对于提供的作用域,它失败了,因为作为传递依赖,它们会被省略.

这是我的意思的一个例子:让我说我将我的项目的Web依赖关系组合成一个web-deps pom.xml.这些包括compile作用域的spring框架依赖项以及provided作用域的javaee:

<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>mvn-web-deps</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>javaee</groupId>
        <artifactId>javaee-api</artifactId>
        <version>${javaee.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

然后我将此pom添加为另一个项目中的依赖项:

<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>project-a</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependency>
    <groupId>com.xyz</groupId>
    <artifactId>mvn-web-deps</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>pom</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)

mvn-web-deps现在,依赖关系变得具有传递性.由于上面的依赖项引用是compile作用域,因此provided省略了传递依赖项.

我想避免将它们添加到dependency父节的部分,因为只能有一个父节点,而一个项目可能只需要其中一些依赖节组,而不是全部.我可以将它们添加到该dependencyManagement部分,但之后我将不得不重新声明每个子项目中的每个依赖项(没有版本).

在避免上述问题的同时对依赖关系进行分组的正确/更好方法是什么?

java dependencies maven-2

8
推荐指数
1
解决办法
6264
查看次数

NoSuchMethodError aspectOf()在运行时从使用iajc构建

我们使用aspectJ来获取现有应用程序的一些指标.在eclipse中使用AJDT进行构建和编织时,一切都很有效.但在整合环境中.我们使用ant脚本来构建和部署应用程序.

问题发生在ExceptionHandler上我确实我们的方面不会抛出异常并破坏应用程序

@Aspect
public class ExceptionHandlerAspect {

    /**
     * Pointcut
     */
    @Pointcut("within(com.xxx.yyy.aop.aspect.*..*)")
    public void allMethodInAspectPackage() {}

    /**
     *  Pointcut
     */
    @Pointcut("!within(com.xxx.yyy.aop.aspect.ExceptionHandlerAspect)")
    public void notInExceptionHandlerAspectClass() {}
    /**
     *  Pointcut
     */
    @Pointcut("call(* *(..))")
    public void allClassAndMethod() {}

    /**
    @Around("allClassAndMethod() && allMethodInAspectPackage() && notInExceptionHandlerAspectClass()")
    public Object logException(ProceedingJoinPoint joinPoint) throws Throwable{
        Object ret = null;
        try {
            ret = joinPoint.proceed();
        }catch (Throwable exception) {
            if (joinPoint.getSignature().getDeclaringTypeName().equalsIgnoreCase("org.aspectj.lang.ProceedingJoinPoint")) {
                throw exception;
            }
            this.logException.info("Exception in " + joinPoint.getSignature().getDeclaringTypeName(),exception);
        }finally {
            return ret; 
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

基本上,我想拦截我的方面包中的每个调用,除了在ExceptionHandler本身.

ant …

aspectj

8
推荐指数
1
解决办法
9117
查看次数

如何在Eclipse中正确使用Tomcat与maven

我正在寻找如何在Eclipse中使用Macat的Tomcat的最佳方法.

我有一些开发Java EE应用程序的经验,并且在使用Maven时我期待类似的行为.

我的要求很简单:

  • 易于应用建设
  • 易于部署
  • 如果可能的话,热插拔

我不知道Tomcat + Eclipse是如何工作的,所以我假设Maven命令

mvn eclipse:eclipse -Dwtpversion=2.0
Run Code Online (Sandbox Code Playgroud)

设置正确的一切,但我怀疑它不能正常工作(或至少如预期的那样).

当项目(让我们称之为测试)在maven中构建时,结果在${project}/target/test文件夹中.但在我看来,Tomcat的类来自不同的文件夹(${project}/target/classes?).这是恕我直言错误(如果我错了,请纠正我),但maven可以在构建类之前做其他操作 - 代码生成,资源过滤,AOP编织等.

有一些建议如何使用它?因为mvn clean install从命令行执行并将结果部署到Tomcat对我来说听起来不像IDE(集成开发环境).有可能指示maven eclipse插件正确设置它吗?

我也尝试使用,mvn tomcat:run但在这里我完全失去了,我得到错误我不明白fe

java.lang.NoSuchMethodError: org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass
Run Code Online (Sandbox Code Playgroud)

并且我不知道为什么它在使用服务器运行时为tomcat 6工作时没有工作.

可以指示Eclipse mvn install在保存类时执行吗?它会起作用吗?这是否足够快(重建只改变了东西+依赖关系,因为我习惯于从标准的JSE项目)?

其实我正在使用

  • maven 3.0.4
  • java 1.6
  • eclipse 4.2.1(STS 3.2.0.M2)
  • tomcat 6(我们目前正在为Tomcat 6开发,但我猜它与7相同)

编辑

pom.xml中的一些相关部分

<project ...>
    <modelVersion>4.0.0</modelVersion>

    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
    <packaging>war</packaging>

    <properties>
        <spring.version>3.1.1.RELEASE</spring.version>
        <!-- WSDL -> Java (start) -->
        <cxf.version>2.7.3</cxf.version>
        <cxf-codegen-plugin.version>2.6.1</cxf-codegen-plugin.version>
        <cxf.sourceRoot>src/main/generated</cxf.sourceRoot>
        <!-- WSDL -> Java (end) -->

        <junit.version>4.11</junit.version>
        <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format> …
Run Code Online (Sandbox Code Playgroud)

java eclipse tomcat maven

8
推荐指数
1
解决办法
4255
查看次数

Spring 3带注释的配置获取@Configuration和@Component,但不是@Controller

所以我正在尝试在没有XML的情况下配置我的Web应用程序并进入所有带注释的路径.我有一些用@Configuration和@Component注释的类被自动拾取,但由于某种原因,我的@Controller注释未被识别并映射到它们对应的@RequestMapping值.

我的web.xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="com-timbuk2-webapp-compositor" 
         version="3.0"
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" >

    <display-name>timbuk2-webapp-Compositor</display-name>

    <!-- Context Parameters -->
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/conf/log4j-config.xml</param-value>
    </context-param>

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </context-param>

    <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>com.company.webapp</param-value>
    </context-param>

    <!-- Listeners -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Filters -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter>
        <filter-name>urlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
        <init-param>
            <param-name>logLevel</param-name>
            <param-value>commons</param-value>
        </init-param>
        <init-param>
            <param-name>confPath</param-name>
            <param-value>/WEB-INF/conf/urlrewrite-config.xml</param-value>
        </init-param>
    </filter>

    <!-- Filter Mappings -->
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>urlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- …
Run Code Online (Sandbox Code Playgroud)

java spring annotations controller spring-mvc

7
推荐指数
1
解决办法
7867
查看次数

保存返回代码并以bash形式返回

我想在bash中这样做

#!/bin/bash

func(){
    return 1;
}

e=func
echo some text
exit e
Run Code Online (Sandbox Code Playgroud)

但我得到了

exit: func: numeric argument required
Run Code Online (Sandbox Code Playgroud)

bash中的AFAIK变量没有类型,如何将其"转换"为int以满足需求?

bash

7
推荐指数
1
解决办法
8853
查看次数