小编res*_*a87的帖子

正则表达式 - 查找具有name属性但不是id的元素

这个问题今天来到我身边.我正在使用包含大量JSP的基于Web的(Struts 2)项目,并且大多数input, select, table和a元素仅使用name属性定义,没有id设置,例如:

<input name="myname" class="myclass" value="" type="text"/>

到目前为止一切都那么好,除了不幸的是这些字段有很多javascript验证,并且我可以在离开大多数代码之前阅读代码实际上引用了元素document.getElementById.

这里的问题是,这是一个旧的应用程序(实际上不是那么老)只与IE-6和IE-7兼容(我没有搜索网络,以了解IE实际上似乎只找到了元素与name属性,但我想它必须做点什么).每个其他单一浏览器都抱怨和哭泣并不奇怪.

所以,我正在尝试提出一个简单的解决方案:查找所有使用该属性定义input, select, table和a元素的JSP,name但不是id为了修复HTML.

使用我的好朋友http://rubular.com我想出了以下内容:

/<(?:(input|select|a|table))\s+((?!id).)*>

这将捕获每个被引用的元素id.但是,我怎么能断言只有那些name匹配的?

哦,另一个重点.元素的定义是一行的,所以最有可能的是:

<input name="..."
       class="..."/>
Run Code Online (Sandbox Code Playgroud)

html regex tags validation

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

Go - 执行无符号移位操作

Go 中是否有执行无符号移位(即无符号右移)操作?Java 中是这样的

0xFF >>> 3
Run Code Online (Sandbox Code Playgroud)

关于此事我唯一能找到的就是这篇文章,但我不确定我必须做什么。

提前致谢。

binary-operators go

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

在Spring Boot MVC中添加ShallowEtagHeaderFilter

我正在尝试调整我的应用程序配置以设置ETag支持.

我刚刚检查了这个问题,所以让我说一下我的代码与它的不同之处:

  1. 我不使用任何xml配置文件.
  2. 我正在为系统的每个方面使用不同的配置类.我WebConfig看起来像这样:

@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = { "xxx", "yyy" })
public class WebConfig extends WebMvcConfigurerAdapter {

   @Bean
   public Filter shallowETagHeaderFilter() {
        return new ShallowEtagHeaderFilter();
   }
      ...
}

  1. 我的SecurityConfig看起来像这样:

    @Configuration
    @EnableWebSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {
        ...

        @Override
        protected void configure(final HttpSecurity http) throws Exception {
            http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and().exceptionHandling()
                        .authenticationEntryPoint(authenticationEntryPoint())
                .and().authorizeRequests()
                        .antMatchers(HttpMethod.GET, "/**").authenticated()
                        .antMatchers(HttpMethod.POST, "/**").authenticated()
                        .antMatchers(HttpMethod.HEAD, "/**").authenticated()
            .and().csrf().disable()    
            .addFilterBefore(authenticationTokenProcessingFilter(), UsernamePasswordAuthenticationFilter.class);
        }

    }

  1. 我还有一个初始化类,它是空的:

    @Order(value=1)
    public class SecurityWebAppInitializer extends AbstractSecurityWebApplicationInitializer {

    }

我没有看到任何地方ShallowEtagHeaderFilter被添加到默认链或任何东西,我如何在此设置中使用它?

etag spring annotations servlet-filters spring-boot

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

Goroutines,频道和僵局

我试图更多地了解go的频道和goroutines,所以我决定制作一个小程序来计算文件中的单词,由bufio.NewScanner对象读取:

nCPUs := flag.Int("cpu", 2, "number of CPUs to use")
flag.Parse()
runtime.GOMAXPROCS(*nCPUs)    

scanner := bufio.NewScanner(file)
lines := make(chan string)
results := make(chan int)

for i := 0; i < *nCPUs; i++ {
    go func() {
        for line := range lines {
            fmt.Printf("%s\n", line)
            results <- len(strings.Split(line, " "))
        }
    }()
}

for scanner.Scan(){
    lines <- scanner.Text()
}
close(lines)


acc := 0
for i := range results {
      acc += i
 }

fmt.Printf("%d\n", acc)
Run Code Online (Sandbox Code Playgroud)

现在,在大多数示例中,我发现到目前为止,lines和results通道都将被缓冲,例如 …

go goroutine channels

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

计算Java 1.4中两个列表的不对称差异

我有两个清单:

List x = [1, 2, 5, 7, 8];
List y = [1, 3, 4, 5];
Run Code Online (Sandbox Code Playgroud)

我试图获得以下计算的不对称差异:

x - y (what's in x that's not in y) => 2 7 8
y - x (what's in y that's not in x) => 3 4
Run Code Online (Sandbox Code Playgroud)

我已经检查了一些关于这个和这个的指针,但我背后有一些限制:

  1. 我正在尝试实现的正是guava的Sets.difference所提供的,除了我坚持使用Java 1.4(我很容易将我的实现从使用Lists更改为Sets)

  2. 使用Collection.removeAll/retainAll将是一个交易破坏者,因为这些方法就地工作.我在列表中保存的对象是一些实际映射到Hibernate的重POJOS.

  3. 从这个意义上说,我需要一些基于散列的实现,因为这个计算已经在那些POJOS中实现了.

底线是,是否有类似Java 1.4的Sets实用程序类?或者可以计算两个集合的不对称差异的东西?

java collections set asymmetric guava

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