qq_30392569
qq_30392569
2015-08-05 14:42
采纳率: 0%
浏览 1.5k

利用Arrays.asList定义固定大小数组时失败

刚开始接触Ajax,实现用户名是否可用要运用到下列函数。。。。
Arrays中的asList总会有下划线提示错误,尝试很多方法都解决不了。
刚开始学,也不是很懂这些代码是什么意思。。用的是jdk1.6.0

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.tribes.util.Arrays;

public class ValiateUserNameServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    List<String> userNames=Arrays.asList("aaa","bbb");
    String result=null;
    if(userNames.contains(userNames)){
        result="<font color='red'>already used</font>";
    }
    else{
        result="<font color='red'>keyishiyong </font>";
    }
    response.setContentType("text/html");
    response.getWriter().print(result);
}

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • caozhy
    
    String[] arr = {"aaa","bbb"};
    List userNames=Arrays.asList(arr);
    
    点赞 评论

相关推荐