小编Mat*_*usz的帖子

Spring MVC + JSON = 406不可接受

我正在尝试生成一个简单的JSON响应.现在我得到406 Not Acceptable错误.Tomcat说:"此请求标识的资源只能根据请求"接受"标题生成具有不可接受特征的响应." 即使我的Accept标题是

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Run Code Online (Sandbox Code Playgroud)

在tomcat/lib中,我有所有Tomcat jar,Spring jar和jackson-all-1.9.0.jar.我正在使用Spring 3.2.2和Tomcat 7.

我知道这个问题已经讨论了很多次,但没有一个解决方案适合我.

web.xml中

<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>Spring Web MVC Application</display-name>

  <servlet>
    <servlet-name>dispatcher</servlet-name>
        <servlet-class>
                  org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

</web-app>
Run Code Online (Sandbox Code Playgroud)

调度员servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
     http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
 <context:component-scan base-package="com.smiechmateusz.controller" />
 <context:annotation-config />

    <mvc:annotation-driven />

</beans>
Run Code Online (Sandbox Code Playgroud)

HelloWorldController.java

package com.smiechmateusz.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import …
Run Code Online (Sandbox Code Playgroud)

java spring json

50
推荐指数
7
解决办法
15万
查看次数

在Firefox中添加指针事件后,光标重置为默认值:无

关于CSS pointer-eventscursorFirefox中的规则之间的CSS关系,我遇到了一个奇怪的行为.当我将一个元素设置为cursor不同于auto(让我们说它的wait)的任何值时,光标的类型会相应地改变,如预期的那样.但是,当我也添加pointer-events: none到同一个元素时,光标将重置为auto.如果我使用同样的事情cursor: wait !important.相同的规则在Chromium和IE(!)中正常工作.

在开始时我认为这可能pointer-events: none是设置时的预期行为,但根据MDN部分关于none值:

该元素永远不是鼠标事件的目标; 但是,如果这些后代将指针事件设置为某个其他值,则鼠标事件可能会以其后代元素为目标.在这些情况下,鼠标事件将在事件捕获/冒泡阶段期间在它们往返于后代的路径上触发此父元素上的事件侦听器.

似乎Javascript事件,而不是CSS事件将不会传播.

现在的问题是:是否有同时使用的方式pointer-events: nonecursor: wait在Firefox中相同的元素?另外,我是否正确解释有关上述摘录的Javascript/CSS事件?

如果重要的话,我在Ubuntu 64bit上使用Firefox 31

这是一个小提琴.在这种情况下,我正在动态添加规则,但仅在使用CSS时会发生相同的情况.我正在谈论的场景是Change cursor to wait --> Disable pointer events

css firefox cursor

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

字符串距离,仅限换位

可能重复:
计算将一个排列转换为另一个排列所需的交换

我正在寻找一种计算某种字符串距离的算法,其中只允许操作是两个相邻字符的转置.例如:
string1:"mother"
string2:"moterh"
距离:2(首先交换"h"与"e"并获得"motehr"然后"h"与"r"导致"moterh")
我知道Damerau -Levenshtein距离这个问题非常相似,但它需要大量的内存(我希望它可以在高达1 000 000个字符的单词上工作得非常快).我已经写过:

int amo = 0;

for (int i = 0; i < n; i++)
{
    if (fromString[i] == toString[i])
        continue;
    char toWhat = toString[i];
    int where = -1;
    for (int j = i; j < n; j++)
    {
        if (fromString[j] == toWhat)
        {
            where = j;
            break;
        }
    }
    while (where != i)
    {
        char temp = fromString[where];
        fromString[where] = fromString[where - 1];
        fromString[where - 1] = temp;
        where--;
        amo++;
    } …
Run Code Online (Sandbox Code Playgroud)

string algorithm edit-distance dynamic-programming levenshtein-distance

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

Spring形式ModelAttribute字段验证,以避免400 Bad Request Error

我有一个ArticleFormModel正常发送的包含数据,html form由Spring使用@ModelAttribute注释注入,即

@RequestMapping(value="edit", method=RequestMethod.POST)
public ModelAndView acceptEdit(@ModelAttribute ArticleFormModel model, 
    HttpServletRequest request, BindingResult errors)
{
    //irrelevant stuff
}
Run Code Online (Sandbox Code Playgroud)

在某些方面,一切都很完美.问题是ArticleFormModel包含一个double字段(protected使用普通的setter设置).只要用户发送的数据是数字,一切正常.当他们输入一个单词时,我得到的只是400 Bad Request Http Error.

我已经WebDataBinder为这个控制器注册了一个

@InitBinder
protected void initBinder(WebDataBinder binder) throws ServletException
{
    binder.setValidator(validator);
}
Run Code Online (Sandbox Code Playgroud)

where validator实现org.springframework.validation.Validator接口的自定义类的实例,但我不知道下一步该做什么.我希望能够解析模型,获得有效的HTTP响应并在表单中显示错误消息.initBinder()调用该方法,我可以从中调用validator.validate(),但它不会更改错误(对于错误的数据).

我知道我可以使用setter来解析字符串,检查它是否为数字,如果没有,将该信息存储在变量中,然后在验证期间检索该变量,但这似乎太多了.必须有一种更简单的方法来强制字段上的类型而不会出现错误.此外,问题在于数据绑定,而不是验证,所以我觉得它应该放在相应的代码层中.

我也在考虑实施java.beans.PropertyEditor和调用binder.registerCustomEditor(),但我缺乏可靠的知识来源.

客户端验证(通过JavaScript检查数据是否为数字)是不可能的.

TL; DR:

如何在@ModelAttribute不获取项目的情况下强制某个字段具有特定类型400 Bad Request Http Error

java spring http-status-code-400 modelattribute

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

Kohana 3.3全能路线

如何定义将捕获所有请求并将其转发到一个特定控制器的路由?我已经尝试添加默认路由了

Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(array(
         'directory' => 'site',
         'controller' => 'foobar',
         'action' => 'foobar',
));
Run Code Online (Sandbox Code Playgroud)

要么

Route::set('default', '(.*)')
    -> defaults(array(
        'directory' => 'site',
        'controller' => 'foobar',
        'action' => 'foobar',
));
Run Code Online (Sandbox Code Playgroud)

到我的bootstrap.php,但它不起作用.键入localhost/a之后我得到了

Unable to find a route to match the URI: a
Run Code Online (Sandbox Code Playgroud)

要么

The requested URL a was not found on this server.
Run Code Online (Sandbox Code Playgroud)

错误.我确信控制器是有效的,如

Route::set('foobar', 'foo') 
    -> defaults(array(
        'directory' => 'site',
        'controller' => 'foobar',
        'action' => 'foobar',
));
Run Code Online (Sandbox Code Playgroud)

工作良好.

我正在使用Kohana 3.3.

php routes kohana

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

php从字符串中查找字符之间的值

考虑字符串1,2,3,4

我想提取1 2 3 4并将其存储在数组中.这段代码

for($i=0; $i<strlen($multi_event_value); $i++)
{
    if(is_numeric(substr($multi_event_value,$i,1)))
    {       
        $multi_event[$t] = substr($multi_event_value,$i,1);
        $t++;
    }
}
Run Code Online (Sandbox Code Playgroud)

工作正常,但如果值是10,11,12,14然后我得到1 0 1 1 1 2 1 4但我希望值为10 11 12 14.如果值为100,101则相同,依此类推.

php string char

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