小编use*_*567的帖子

JQuery只允许小数点后的两个数字

我在这里发现了以下JQuery函数,它阻止用户输入任何不是数字或单个小数的内容.该功能运行良好但我想改进它以防止用户输入3个或更多小数位,即禁止99.999并允许99.99.有任何想法吗?

 function checkForInvalidCharacters(event, inputBox){                            
     if ((event.which != 46 || inputBox.val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {          
                event.preventDefault();           
            }   
     };
Run Code Online (Sandbox Code Playgroud)

javascript jquery keycode

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

将列表传递给Android中的另一个活动

我创建了一个列表,并希望将列表传递给另一个活动,但是当我创建intent时,我在putExtra语句中收到错误.只是想知道是否有任何简单的方法来传递字符串列表而不是单个字符串?

谢谢

private List<String> selItemList;
private ListView mainListView = null;       

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recipes);
        Button searchBtn = (Button) findViewById(R.id.searchButton);
        searchBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (selItemList == null) {
                Toast.makeText(getApplicationContext()," Please Make A Selection ", Toast.LENGTH_SHORT).show();
            } else {
                Intent intent = new Intent(Recipes2.this, XMLParser.class);
                intent.putExtra("items_to_parse", selItemList);
                startActivityForResult(intent, 0);              
            }
        }
        });
Run Code Online (Sandbox Code Playgroud)

android parameter-passing android-intent android-activity

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

@ControllerAdvice Not Firing

我正在开发一个Spring MVC/Webflow应用程序(版本3.2),并试图让异常处理工作,我可以将自定义异常消息输出到日志文件和error.jsp.我遇到的问题是异常处理程序没有被解雇.我创建了以下类并对其进行了注释@ControllerAdvice,并将其放入与抛出异常的控制器相同的包中:

@ControllerAdvice
public class MyCustomExceptionController {

    @ExceptionHandler(MyCustomException.class)
    public ModelAndView handleMyException(MyCustomException ex) {   
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/error/error");
        modelAndView.addObject("errorId", ex.getErrorId());
        modelAndView.addObject("message", ex.getErrorMessage());        
        return modelAndView;
    }
}
Run Code Online (Sandbox Code Playgroud)

并将以下内容添加到mvc-config文件中:

<mvc:annotation-driven/>
Run Code Online (Sandbox Code Playgroud)

并在我的app-config文件中包含以下内容:

<context:component-scan base-package="package containing my controllers and MyCustomExceptionController">
        <context:include-filter type="annotation" 
    expression="org.springframework.web.bind.annotation.ControllerAdvice" />
    </context:component-scan> 
Run Code Online (Sandbox Code Playgroud)

任何想法为什么这不起作用?

java spring exception-handling spring-mvc

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

嵌入式Jetty服务器类路径问题

我正在尝试在嵌入式Jetty服务器上部署Web应用程序.我的应用程序在Windows环境中使用下面的代码在本地运行良好,但是当我在Linux服务器上将其部署为JAR文件时,看起来我的web.xml文件没有被选中.在构建JAR之前,我是否需要在下面的Descriptor或ResourceBase字段中更改某些内容?

static void startJetty() {
        try {
            Server server = new Server(9090); 
            WebAppContext context = new WebAppContext();
            context.setDescriptor("/WEB-INF/web.xml");                     
            context.setResourceBase("../DemoWithMultiChannels/src/");
            context.setContextPath("/");            
            context.setParentLoaderPriority(true);   
            server.setHandler(context);

            System.out.println("Starting Server!");             
            server.start(); 
Run Code Online (Sandbox Code Playgroud)

web.xml embedded-jetty

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

Spring Boot 太多重定向

我正在使用 Thymeleaf & Spring Boot 开发一个简单的登录表单。当我尝试在 Chrome 中访问以下 URL 时:“ http://localhost:8080/login ”我收到一条错误消息,提示“ERR_TOO_MANY_REDIRECTS”。我尝试清除浏览器中的缓存和 cookie,但仍然出现相同的错误。

我尝试通过将以下属性放入我的 application.properties 来禁用默认安全登录屏幕: security.basic.enabled=false

并将以下配置添加到我的 SecurityConfig 中,以便除“/login”和“/resources”之外的任何 URL 都可以通过身份验证:

@Configuration 
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired 
    private UserRepository userRepository;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
        .authorizeRequests()
            .antMatchers("/resources/**").permitAll()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
        .logout()
            .permitAll();
    }
Run Code Online (Sandbox Code Playgroud)

我的 LoginController 很直接:

@Controller
public class LoginController {

        @RequestMapping(value="/login", method=RequestMethod.GET)
        public String loadForm(Model model) {
            model.addAttribute("user", new User());
            return "redirect:/login";
        }
Run Code Online (Sandbox Code Playgroud)

任何人都知道为什么会发生这种情况?

spring-boot

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

无法更新应用程序:无法编译JSP文件

我正在尝试在App Engine上首次部署应用程序,并且我收到错误消息"无法更新应用程序:无法编译JSP文件".任何人有任何想法如何解决这个问题.我已经将eclipse设置为指向Windows/Preferences/Java/Installed JRE中的JDK1.6.0_17.我的JAVA_HOME当前设置为"C:\ Program Files\Java\jdk1.6.0_17".我还编辑了"appengine-java-sdk-1.4.2\bin"文件夹中的appcfg.cmd文件,如下所示:

@"%JAVA_HOME%"\bin\java -cp "%~dp0\..\lib\appengine-tools-api.jar" com.google.appengine.tools.admin.AppCfg %*

任何想法为什么会这样?

谢谢

google-app-engine jsp compiler-errors

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

将逗号分隔的字符串添加到ArrayList,反之亦然

如何将逗号分隔的字符串添加到ArrayList?我的字符串"returnedItems"可能包含1或20个项目,我想将它添加到我的ArrayList"selItemArrayList"中.

在填充ArrayList后,我想以后通过它遍历和格式化的项目与项目之间没有空格的逗号分隔字符串.

java csv arraylist

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

从 Servlet 访问 Spring Bean

我在 applicationContext 中定义了一个 Spring Bean,如下所示:

<bean id="spaceReader" class="com.company.SpaceReader">
</bean>
Run Code Online (Sandbox Code Playgroud)

我希望能够在我的应用程序 Servlet 中访问此 bean,而无需使用:

ApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_LOCATION);
context.getBean("SpaceReader");
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下命令导出它:

<bean id="ContextExporter" class="org.springframework.web.context.support.ServletContextAttributeExporter">
    <property name="contextExporterAttributes">
        <map>
            <entry key="SpaceReaderKey">
            <ref local="spaceReader" />
        </entry>
        </map>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

但是当我将它注入到 Servlet 中时,它返回一个 Null 值。只是想知道当我导出 Bean 或当我尝试在 Servlet 中访问它时是否缺少某些内容?

spring

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

验证包含2个小数位的double的简单方法是什么?

我正在寻找一个Java示例来检查用户输入的双金额是否包含2位小数,例如输入的99.99将返回有效,输入的99.9或99.999将返回无效.

java

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