| public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws ServletException, IOException { doGet(httpservletrequest, httpservletresponse); } public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws ServletException, IOException { String s = ""; String s1 = ""; s = HttpUtils.getRequestURL(httpservletrequest).toString(); file://返回一个字符串,包含请求字符串中包含的协议名,主机名,端口号以及路径,但是不包含请求的内容 int i; if((i = s.indexOf("?")) > 0)//去掉s结尾的问号 s = s.substring(0, i); s1 = httpservletrequest.getQueryString();//取的请求字符串的请求内容 if(s1 == null) { parseFile(s1, httpservletrequest, httpservletresponse); return; } if(s1.equals(admin)) file://如果请求串等于admin { adminPage(httpservletrequest, httpservletresponse, s); file://进入管理员界面 return; } if(s1.equals("namiotde")) file://如果请求串为namiotde,则执行相应的执行命令 { executeRequest(httpservletrequest, httpservletresponse); return; } String s2 = getFromQuery(s1, "what="); file://取的动作的属性值 if(s2.equals("hframe")) { getHiddenFrame(httpservletrequest, httpservletresponse);//转到隐藏帧 return; } if(s2.equals("mframe")) { getMainFrame(s1, httpservletrequest, httpservletresponse); file://转到主帧 return; } else { parseFile(s1, httpservletrequest, httpservletresponse); return; } } file://管理员界面,执行添加删除对象的操作 private void adminPage(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s) throws IOException { PrintWriter printwriter = httpservletresponse.getWriter(); String s1 = ""; String s4 = httpservletrequest.getParameter("what"); file://返回请求串中what,即动作的属性值 if(s4 != null) if(s4.equals("delete")) file://如果what的值为delete,则执行相应的操作 { for(Enumeration enumeration = httpservletrequest.getParameterNames(); enumeration.hasMoreElements();) { String s2 = (String)enumeration.nextElement(); if(s2.startsWith("_")) { inst.remove(s2.substring(1)); s1 = s1 + " " + s2.substring(1); } } if(s1.length() > 0) s1 = "删除: " + s1; } else if(s4.equals("add")) file://如果what的值为add,则执行相应的操作 { String s5 = httpservletrequest.getParameter("oname");//取的对象名 String s6 = httpservletrequest.getParameter("JinJ"); file://取得类名 String s7 = httpservletrequest.getParameter("params"); file://取得参数 if(s5 == null) s5 = ""; else s5 = s5.trim(); if(s6 == null) s6 = ""; else s6 = s6.trim(); if(s7 == null) s7 = ""; else s7 = s7.trim(); if(s7.length() > 0 && !s7.startsWith("(")) s7 = "(" + s7 + ")"; if(s5.length() > 0 && s6.length() > 0 && inst.size() < 5) { String s3 = s5 + "=new " + s6 + s7;//写成标准的对象实例化形式 if(processLine1(s5, s6, s7, s3)) s1 = s5 + " 被载入..."; else s1 = "不能载入" + s3; } } httpservletresponse.setContentType("text/html"); printwriter.println("<html>"); printwriter.println("<head>"); printwriter.println("<title>JinJ 控制台</title>"); printwriter.println("</head>"); printwriter.println("<body bgcolor=\"#FFFFFF\">"); printwriter.println(setScript()); if(s1.length() > 0) printwriter.println("<br><i>" + s1 + "</i><br>"); printwriter.println("<h2><center>对象</center></h2>"); printwriter.println("<br>"); printwriter.println(objectsTable(s)); printwriter.println("</body>"); printwriter.println("</html>"); } |
| private String setScript() { StringBuffer stringbuffer = new StringBuffer(); stringbuffer.append("<script language=\"JavaScript\">" + NEWLINE); stringbuffer.append("function fun(what)" + NEWLINE); stringbuffer.append("{ document.mf.what.value=what; document.mf.submit(); }" + NEWLINE); stringbuffer.append("</script>" + NEWLINE); return stringbuffer.toString(); } private String objectsTable(String s) { StringBuffer stringbuffer = new StringBuffer(); String s2 = "#D5E6E1"; stringbuffer.append("<form name=\"mf\" method=post action=\"" + s + "?" + admin + "\">" + NEWLINE); stringbuffer.append("<input type=hidden name=\"what\">" + NEWLINE); stringbuffer.append("<table width=98% border=0>"); stringbuffer.append("<tr bgcolor=#CCCCFF><td nowrap> </td><td nowrap>对象名</td><td nowrap>类名</td></tr>" + NEWLINE); for(Enumeration enumeration = inst.keys(); enumeration.hasMoreElements();) { String s1 = (String)enumeration.nextElement(); Object aobj[] = (Object[])inst.get(s1); stringbuffer.append("<tr bgcolor=\"" + s2 + "\">"); stringbuffer.append("<td width=5 nowrap>"); stringbuffer.append("<input type=checkbox name=\"_" + s1 + "\">"); stringbuffer.append("</td>"); stringbuffer.append("<td nowrap>" + s1 + "</td><td nowrap>" + aobj[0] + "</td></tr>" + NEWLINE); if(s2.equals("#D5E6E1")) s2 = "#F7F7F7"; else s2 = "#D5E6E1"; } stringbuffer.append("</table>" + NEWLINE); stringbuffer.append("<br><br>"); stringbuffer.append("<table>" + NEWLINE); stringbuffer.append("<tr>"); if(inst.size() > 0) stringbuffer.append("<td align=left nowrap><input type=button value=Delete onClick=\"fun('delete');\"></td>"); else stringbuffer.append("<td nowrap> </td>"); stringbuffer.append("<td nowrap> </td>"); stringbuffer.append("<td align=right nowrap>对象名 <input type=text size=10 name=\"oname\"> 类名 <input type=text size=18 name=\"JinJ\"> 参数 <input type=text name=\"params\"> "); stringbuffer.append("<input type=button value=Add onClick=\"fun('add');\"></td></tr>"); stringbuffer.append("</table>" + NEWLINE); stringbuffer.append("</form>"); return stringbuffer.toString(); } file://分析文件 private void parseFile(String s, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws IOException { String s1 = getUrl(httpservletrequest); String s2 = getFile(s, httpservletrequest); httpservletresponse.setContentType("text/html"); PrintWriter printwriter = httpservletresponse.getWriter(); printwriter.println("<html>"); if(s1 == null) { printwriter.println("<br>找不到servlet名.请检查初始参数"); } else { printwriter.println("<frameset rows=\"*,100%\" border=0>"); printwriter.println("<frame name=\"hframe\" src=\"" + s1 + "?" + "what" + "=" + "hframe" + "\">"); printwriter.println("<frame name=\"mframe\" src=\"" + s1 + "?" + "what" + "=" + "mframe" + "&" + "df" + "=" + s2 + "\">"); printwriter.println("</frameset>"); } printwriter.println("</html>"); printwriter.flush(); printwriter.close(); } |
转载保留:http://www.qqread.com/java/e820899060.html
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- Java环境安装配置 (5627篇文章)
- Java编程开发手册 (8276篇文章)
- 掌握JAVA的标准 (26次浏览)
- Ubuntu Linux系统中Java环境的安装配置 (25次浏览)
- JAVA编译时的常见错误 (25次浏览)
- 系统构建高性能J2EE应用的五种核心策略 (18次浏览)
- 如何在MyEclipse快速搭建Hibernate应用 (15次浏览)
- Nhibernate与代码生成器介绍 (14次浏览)
- 高手为你分析类的设计方法 (12次浏览)
- Java中利用反射实现类的动态加载 (12次浏览)
- JAVA运行时的产间错误 (11次浏览)
- J2SE综合:浅谈java程序发布之 jre 篇 (11次浏览)



