体验通过语音来操作Vista,使梦想成为可能
2007-10-19 09:41
260 查看
web.xml
action-config.xml
ActionServlet.java
Action1.java
用了dom4j解析xml配置文件,希望高手批评执教.
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>testmvc</display-name> <servlet> <servlet-name>actionServlet</servlet-name> <servlet-class>mvc.ActionServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>actionServlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
action-config.xml
<?xml version="1.0" encoding="UTF-8"?> <action-mapping> <action id="ac1" class="action.Action1"></action> <action id="ac2" class="action.Action2"></action> </action-mapping>
ActionServlet.java
public class ActionServlet extends HttpServlet{ private static final String ACTION_CONFIG_NAME = "action-config.xml"; private static Document doc = null; private static Map<String,String> actionMap = null; @Override public void init() throws ServletException { try { initConfig(); } catch (DocumentException e) { e.printStackTrace(); System.exit(-1); } } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String reqUri = fomartUri(req.getContextPath(), req.getRequestURI()); if(actionMap.containsKey(reqUri)) { try { Class clazz = Class.forName(actionMap.get(reqUri)); clazz.getMethod("execute",HttpServletRequest.class,HttpServletResponse.class).invoke(clazz.newInstance(),req,resp); } catch (Exception e) { e.printStackTrace(); } } } private void initConfig() throws DocumentException { SAXReader reader = new SAXReader(); doc = reader.read(ActionServlet.class.getClassLoader().getResourceAsStream(ACTION_CONFIG_NAME)); actionMap = new HashMap<String, String>(); Element element = null; for(Object obj : doc.selectNodes("/action-mapping/action")) { element = (Element)obj; actionMap.put(element.attributeValue("id"), element.attributeValue("class")); } } // /testmvc/ac1.do private String fomartUri(String contextPath, String str) { return str.replaceAll(".do", "").replaceAll(contextPath + "/", ""); } }
Action1.java
public class Action1 { public void execute(HttpServletRequest req, HttpServletResponse resp) { try { resp.getWriter().println(Action1.class.getName()); } catch (IOException e) { e.printStackTrace(); } } }
用了dom4j解析xml配置文件,希望高手批评执教.
相关文章推荐
- 体验 Vista Speech Recognition,使梦想成为可能
- 项目经验谈之三——通过操作提交按钮可见性提升用户体验
- 解决多线程操作控件时可能出现的异常:“在某个线程上创建的控件不能成为在另一个线程上创建的控件的父级”
- 如何成为自己所在领域内前1%的顶尖人才? 凤凰科技 09-29 07:42 原标题:如何成为自己所在领域内前1%的顶尖人才? 有时你会觉得,可能你永远也实现自己的梦想。你清楚地知道自己想做什么,但有
- Win7系统如何通过口令操作电脑 设置使用语音操作Win7系统图文教程
- Siri让语音购物成为可能
- 体验Vista三个特性 鲜为人知的有趣操作
- mybatis3通过provider注解结合动态sql实现增删改查,不再依赖xml成为可能
- ThinkPad X60 BM8 + Vista Enterprise 前爽未有的操作体验
- 决多线程操作控件时可能出现的异常:“在某个线程上创建的控件不能成为在另一个线程上创建的控件的父级”
- Android-通过语音来操作微信
- 只能通过语音控制的概念型音乐播放器乐流Music Flow:想要带给用户最原始的交互体验,说出你想听的音乐
- 利用Java操作Office2007成为可能
- 解决多线程操作控件时可能出现的异常:“在某个线程上创建的控件不能成为在另一个线程上创建的控件的父级”
- 给自己一个看似不可能是想的梦想,它一定会成为奋斗的发动机~!
- 一些操作和C++语言本身的特性可能成为应用程序的瓶颈
- 通过jdbc对数据库操作
- MFC 通过发送消息完成按钮操作模拟鼠标单击事件的发生的问题
- Delphi之通过ADOX操作access数据库
- Hive基本操作 通过java连接