小编Lui*_*oza的帖子

Java String to Integer Conversion抛出NumberFormatException

我想将一个字符串(二进制数字)转换成Integer如下所示:

Integer.parseInt("011000010110")
Run Code Online (Sandbox Code Playgroud)

我总是得到一个NumberFormatException.数字位数太高了吗?

java

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

是否可以缩短方法的参数?

是否可以缩短java中方法的参数.

例如

public void testing(String A, String B, String C, JButton A, JButton B, JButton C){
}
Run Code Online (Sandbox Code Playgroud)

由于我有3个String变量和3个按钮,因此可以以任何方式缩短它.我试过了String A,B,C JButton A,B,C但是没有用.

java methods swing

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

我应该使用哪种类型的数组

我想创建一个包含播放器列表以及它们所在的竞技场的数组.我不知道哪种类型的阵列最适合.

它将保存这样的信息:

PlayerName : Arena
John : Arena1
Harry : Arena1
Dave : Arena2
Will : Arena2
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助,我是Java的新手,无法在网站上看到这个,如果是,请指向我那个方向:)

java arrays

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

servlet被调用的次数随着获取的请求数量而增加

我有以下代码,

public class HttpAdapter extends HttpServlet {
    private static final long serialVersionUID = 1L;
    static Logger l = Logger.getLogger(HttpAdapter.class.getName());

    public HttpAdapter() {
        super();     
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try{
            Layout ll = new SimpleLayout();
            Appender a = new FileAppender();
            a = new FileAppender(ll,"C:\\Users\\Vasanth\\Desktop\\JDlogs\\my.txt");
            l.info(request.getRemoteHost());
            l.addAppender(a); 

            String loc = DTO.findMyLocation();      
            l.info(loc);

            l.info(this.getClass()+" >>>>>>>>>>>>>>task complete");
            l.info(request.getRemoteHost());

        }catch(Exception e){
            e.printStackTrace();        
        }finally{
            getServletContext().getRequestDispatcher("/JSP/done.jsp").forward(request, response);
        }

    }
    //F:\\home\\WorkSpace\\Jdfront1\\webapps\\JSP\\

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    } …
Run Code Online (Sandbox Code Playgroud)

java jsp tomcat servlets

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

数组索引超出界限异常,我不知道为什么

我不明白为什么这会超出范围,你能帮助我吗?

会发生什么:

  • 用户输入列表的长度
  • 用户输入列表中的所有项目,仅提示,直到达到用户输入的列表(a)的长度.

出于某种原因,在列表中的第一项之后,它超出范围,但我不知道为什么.

import java.util.Scanner; //import scanner

public class project2 {

public static void main (String[] args){

    Scanner input = new Scanner(System.in); //scanner for input

    int a = 0;
    double [] lista = new double [a]; //create array
    double [] listb = new double [a]; //create array

    System.out.println("How long are the lists? ");
    System.out.print("(The lists should be the same length):  ");
    a = input.nextInt();

    int count=1;
    System.out.println("Enter numbers for list A:");
    for(int j = 0; j < a-1 …
Run Code Online (Sandbox Code Playgroud)

java list indexoutofboundsexception

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

奇数或偶数的条件运算符

我正在尝试编写一个程序,如果在给定的数量中存在相同数量的赔率和偶数,它会工作得很好但是它想要使用条件运算符而不是这4行(//行),

我明白了:

令牌"%"上的语法错误,AssignmentOperator无效

有人可以告诉我为什么吗?怎么了?

while(number!=0) {
    //if(number%2==0)
    //even++;
    //else
    //odd++;
    number%2==0 ? even++ : odd++;
    number/=10;
}
Run Code Online (Sandbox Code Playgroud)

java

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

提高Java Web Application的性能

我正在使用具有以下技术堆栈的3层Web应用程序:

  • Java EE
  • Servlet 3.0
  • JSP 2.4
  • 春天3.0
  • MySQL数据库
  • Tomcat Web服务器

我们使用Mozilla Firefox浏览器启动此应用程序.我的问题是,应用程序在数据库上有大量数据时会遇到性能问题.

我们有大约10个JSP,而每个JSP与数据库中的特定表相关.加载表中包含大量数据的特定JSP时会出现此问题.登录到应用程序也遇到了性能问题,这也需要很长时间才能显示主页.

我需要这个应用程序以最佳性能工作.由于性能问题,我们不想失去我们宝贵的客户.我不知道瓶颈在哪里,以及如何调整应用程序的性能.

java web-applications

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

@Autowire在servlet中为null

如果我使用@Autowired,这个servlet中的服务为null,它使用context.getBean(); 此外,使用/ floorOperationWS /的映射没有完成,我必须在web.xml中定义映射.

package com.confloorapp.services.endpoint;

import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;



@WebServlet(value = "/floorOperationWS/")
public class UpdateFloorEventServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());


            FloorService floorService = (DoorService)context.getBean("floorService");

}



}
Run Code Online (Sandbox Code Playgroud)

这里是applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:sws="http://www.springframework.org/schema/web-services"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.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
            http://www.springframework.org/schema/web-services 
            http://www.springframework.org/schema/web-services/web-services-2.0.xsd">

    <!-- Activates various annotations to be …
Run Code Online (Sandbox Code Playgroud)

java spring servlets spring-mvc

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

构造函数重载相同的参数

假设我有2个字段的类:x和y,类型double.是否可以定义2个构造函数,因此constructor1将创建对象,将其x属性设置为构造函数中的哪个参数告诉y默认值,构造函数2反之亦然?

public class Test {

    private int x;
    private int y;

    public Test(int x) {
        this.x = x;
    }

    public Test(int y) {
        this.y = y;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试这样的东西,我知道它因为超载规则而无法工作

java constructor overloading

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

使用带有自动增量字段的预准备语句

我试图插入一个表,其主键设置为使用预准备语句自动递增.

表中的字段如下;

id,用户名,密码,电子邮件,名字,姓氏

我的代码是这样的

    String sql = "INSERT INTO Users values (?,?,?,?,?, ?)";
    RegistrationStatus status = null;
    Connection conn = null;
    PreparedStatement st = null;
    try {
        conn = source.getConnection();
        st = conn.prepareStatement(sql);
        st.setString(2, username);
        st.setString(3, password);
        st.setString(4, email);
        st.setString(5, firstname);
        st.setString(6, lastname);
        st.executeUpdate();
Run Code Online (Sandbox Code Playgroud)

在我读过的地方,我们不应该包含第一个项目,因为数据库会处理它.对我而言,这种方法似乎失败了.

是否可以获得一些如何解决这个问题的帮助?

java sql prepared-statement

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