这几天学习了servlet,struts及hibernate,我自我感觉都不难就是不知道怎么学,例如struts in action的第一个例子,里面的不全代码可以在网上搜索得到,调试时候不论你怎么输入密码,两次密码是否一致,都会转向同一界面failure.html,使用System.out输出异常,发现竟然是app.UseDirectoryException这个出现的问题,于是我又写了一个test主类调用UserDirectory类,发现如下异常 java.io.FileNotFoundException: C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%205.5/webapps/register/WEB-INF/classes/resources/users.properties (系统找不到指定的路径)乖乖啊,我的register.war是放在tomcat的webapps目录下,users.properties 就是放在register/WEB-INF/classes/resources目录下,系统竟然找不到啊,于是我又配置了虚拟路径register.xml <Context path="/register" docBase="e:/register" debug="0" reloadable="true"> </Context>结果竟然发现可以了。这样只要是两次密码一致,就可以注册成功了!这是e的test package app;public class test{ public static void main(String args[]){ try { UserDirectory.getInstance().setUser("mengshan","1986"); System.out.println("注册成功"); //return mapping.findForward("liberty"); } catch (UserDirectoryException e) { System.out.println("出错原因"+e.toString()); // return mapping.findForward("failure"); } }}
我还把UserDirectory给改动了方便异常输出啊 public void setUser(String userId, String password) throws UserDirectoryException { // no nulls if ((null==userId) || (null==password)) { throw new UserDirectoryException(); } try { // conform userId to uppercase when stored p.put(fixId(userId), password); String o = this.getClass().getClassLoader().getResource(UserDirectoryFile).getFile(); p.store(new FileOutputStream(o), UserDirectoryHeader); } catch (IOException e) { // throw new UserDirectoryException(); System.out.println(e.toString()); } } }
不知道为什么java对目录太深的竟然提示io异常啊,