还是老问题,一直没有得到回答:
如何:写一个 jsp 或 bean,修改 tomcat 的 tomcat-users.xml 里的用户密码。
升双星啦,给弟兄们表示表示。答对的赠50分,其它人按跟贴顺序赠5分,赠完为止。共发 3 贴,600分。
另外两贴:
http://community.csdn.net/Expert/topic/4872/4872289.xml?temp=.3835413
http://community.csdn.net/Expert/topic/4872/4872295.xml?temp=.2579309

解决方案 »

  1.   

    下载tomcat的源代码。看它是如何对tomcat-users.xml 里面的用户名和密码进行修改的。
      

  2.   

    to: nirvana_li(东成西就,芝兰境界)我知道要去研究tomcat的源码,我只是奇怪,为什么没有人能给出答案呢?不瞒你说,我已经找到答案了,只想用这个问题把csdn里的高手引出来。
      

  3.   

    SAXBuilder sb = new SAXBuilder();
            Document myDocument = sb.build("tomcat-users.xml");
            Element root = myDocument.getRootElement();
            XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
            
            root.setAttribute("comment","introduce myself");
            
            List eleList = root.getChildren("user");
            
            Iterator it = eleList.iterator();
            while(it.hasNext()){
             Element ele = (Element) it.next();
            
             if(args[0].equals(ele.getAttributeValue("username"))){
             ele.setAttribute("password",args[1]);
             }
            
            }
            xmlOut.output(myDocument,System.out); 好像没改到XML文件里面,不知道最后还要怎么保存更改的数据XMLBEANS 里面确是可以更改,不过还要把XML生成Schema文件
    http://www.matrix.org.cn/resource/article/44/44027_XMLBean.html
      

  4.   

    恭喜升级!step 1:定位xml文件      File file = new File("../conf/tomcat-users.xml");
    step 2:xml操作          通过XSLT方法或XmlDocument修改后写回去。
                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
                ……
      

  5.   

    其实,如果是我处理这个问题的话,就直接用JDOM,然后对XML文档进行处理,然后就可以了结了。