小编Sau*_*pta的帖子

由于servlet文件导致xml错误找不到元素的声明,引用文件包含错误

我不知道为什么会发生这些错误有人可以解释我如何解决它们 -

  1. cvc-elt.1: Cannot find the declaration of element 'web_1:web-app'.
  2. Referenced file contains errors (jar:file:/C:/Program Files/eclipse/plugins/org.eclipse.jst.standard.schemas_1.2.0.v201101142102.jar!/dtdsAndSchemas/web-app_2_5.xsd). For more information, right click on the message in the Problems View and select "Show Details..."

这是我面临的两个错误,因为我错误地添加了一个servlet,我打算在我的项目中添加一个普通的类文件..然后这两个错误开始显示甚至我删除了servlet文件.这是我的xml代码(实际上它是基本代码) - 因为我还没有使用过单个servlet文件,我只使用了jsp文件.

仍然是xml文件 -

<?xml version="1.0" encoding="UTF-8"?>
    <web_1:web-app
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
        xmlns:web_1="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id="WebApp_ID"
        version="3.0">
        <display-name>InitialD</display-name>
        <web_1:welcome-file-list>
            <web_1:welcome-file>index.html</web_1:welcome-file>
            <web_1:welcome-file>index.htm</web_1:welcome-file>
            <web_1:welcome-file>index.jsp</web_1:welcome-file>
            <web_1:welcome-file>default.html</web_1:welcome-file>
            <web_1:welcome-file>default.htm</web_1:welcome-file>
            <web_1:welcome-file>default.jsp</web_1:welcome-file>
        </web_1:welcome-file-list>
    </web_1:web-app>
Run Code Online (Sandbox Code Playgroud)

java eclipse apache jsp servlet-3.0

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

如何在SortedSet <>上定义比较器,如TreeSet <>?

我想制作一个词汇排序的字符串列表,所以我选择了基本的SortedSet

1)  Set<String> words = new SortedSet<String>(){}
Run Code Online (Sandbox Code Playgroud)

并意识到SortedSet是一个抽象类,我将不得不实现comapartor方法.所以我去google搜索并发现treeSet更好,我可以使用它预定义的比较器方法.

2)  SortedSet<String> words = new TreeSet<String>(){}
Run Code Online (Sandbox Code Playgroud)

当去了java文档时,我意识到TreeSet扩展了AbstractSet而不是SortedSet.问题1 -任何人都可以解释第二行是如何工作的(就像我没有概括我通常会做的集合,而是使用两个完全不同的类,没有父子关系). 问题2 - 如何定义SortedSet的比较器,它将用作TreeSet.所以这是使用TreeSet的工作代码

SortedSet<String> words = new TreeSet<>();
    Scanner scanner1 = new Scanner(System.in);
    String s1 = scanner1.nextLine();
    int a = scanner1.nextInt();
    while(s1.length()>a){
        words.add(s1.substring(0,a));
        s1 = s1.substring(a);
    }
    Iterator itr  = words.iterator();
    while(itr!= null&&itr.hasNext()){
        System.out.println(itr.next());
    }
Run Code Online (Sandbox Code Playgroud)

正常输入

welcometojava
3
Run Code Online (Sandbox Code Playgroud)

预期产出

com
eto
jav
wel
Run Code Online (Sandbox Code Playgroud)

编辑-1对于问题2的答案,我期待这样的事情

Set<String> words = new SortedSet<String>() {
        @Override
        public Comparator<? super String> comparator() {
            return null;
        }
        ......
Run Code Online (Sandbox Code Playgroud)

我基本上想学习,如何在使用 …

java collections set

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

标签 统计

java ×2

apache ×1

collections ×1

eclipse ×1

jsp ×1

servlet-3.0 ×1

set ×1