|
参考: http://www.duduwolf.com/wiki/2007/296.html http://www.chinaitpower.com/A/2005-07-03/150232.html1)普通的Bean处理 不管是什么Set参数为3个 ( 对象本身, 属性名或属性内位置, 值 ) //list的add有点特别 Get参数为2个 ( 对象本身, 属性名或属性内位置 ) Employee em = new Employee(); //String name; String[] ss; Map map; List list; BeanUtils.setProperty(em,"name","liukaiyi"); //String set BeanUtils.setProperty(em,"ss",new String[]{"1","2","3"}); //String[] set BeanUtils.setProperty(em,"ss[2]","google"); //String[2] set
BeanUtils.setProperty(em,"map",new HashMap()); //Map set BeanUtils.setProperty(em,"map(key)","value"); //Map.put(Key,Value) BeanUtils.setProperty(em,"list",new ArrayList( Arrays.asList( new Object[20] ) )); //List有点特别 BeanUtils.setProperty(em,"list[0]","list"); //不可以直接添加??? BeanUtils.setProperty(em,"avg","23"); //int set System.out.println( BeanUtils.getSimpleProperty(em,"name") ); System.out.println( BeanUtils.getProperty(em,"ss[2]") ); System.out.println( BeanUtils.getProperty(em,"map(key)") ); System.out.println( BeanUtils.getProperty(em,"list[0].class") ); // 取的是 ==list.get(0).getClass() System.out.println( BeanUtils.getProperty(em,"avg") );
2)动态属性 //定义动态属性集 DynaProperty[] props = new DynaProperty[]{ new DynaProperty("address", java.util.Map.class), new DynaProperty("subordinate", mypackage.Employee[].class), new DynaProperty("firstName", String.class), new DynaProperty("lastName", String.class) }; //创建动态类来设定动态属性值 BasicDynaClass dynaClass = new BasicDynaClass("employee", null, props); DynaBean employee = dynaClass.newInstance(); employee.set("address", new HashMap()); employee.set("subordinate", new mypackage.Employee[0]); employee.set("firstName", "Fred"); employee.set("lastName", "Flintstone");
//也可以同上一样 提供统一 的Get Set 还是 字符操作 ^o^ 哈哈 BeanUtils.setProperty(bean,"address",new HashMap()); BeanUtils.setProperty(bean,"address(ads1)","江西"); BeanUtils.setProperty(bean,"name","liu"); BeanUtils.setProperty(bean,"subordinate",new String[3]); BeanUtils.setProperty(bean,"subordinate[1]","heha"); System.out.println( BeanUtils.getProperty(bean,"address(ads1)") ); System.out.println( BeanUtils.getProperty(bean,"name") ); System.out.println( BeanUtils.getProperty(bean,"subordinate[1]") );
3)JDBC 扩展 Connection conn = ; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery ("select accountid, name from customers"); Iterator rows = (new ResultSetDynaClass(rs)).iterator(); //ResultSetDynaClass(java.sql.ResultSet resultSet) while (rows.hasNext()) { //利用动态bean进行输出 DynaBean row = (DynaBean) rows.next(); //连实体Bean都可以不要了 BeanUtils.copyProperties( MyBean ,row ); // bean<--dynaBean 就这样去得到值 ^o^ MyBean.getAccountid(); .... } rs.close(); stmt.close(); 4)HttpServletRequest 扩展 HttpServletRequest request = ; MyBean bean = ; HashMap map = new HashMap(); Enumeration names = request.getParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); map.put(name, request.getParameterValues(name)); } BeanUtils.populate(bean, map);//bean<--map struts好象是就用这个 Form
问题:
当IE 禁用javascript 怎么验证数据 解决:Struts validation 框架 1)先 建 Form类 extendsValidatorForm private String name ; private String pass ;
2) Jsp 建立
<body> <font color="red" ><html:errors/></font> <html:form action="/test"> name:<html:text property="name" /> pass:<html:text property="pass" /> <html:submit>submit</html:submit> </html:form> </body> 3)validator.xml建立
<?xml version='1.0'?> <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"> <form-validation> <formset> <form name="testForm"> <field property="name" depends="minlength,maxlength,mask"> <msg name="minlength" key="err.minlength" /> <!-- 当 minlength错时 msg 激活 --> <msg name="maxlength" key="err.maxlength" /> <arg0 key="${var:maxlength}" resource="false"/> <arg1 key="${var:minlength}" resource="false"/> <var> <var-name>maxlength</var-name> <var-value>5</var-value> </var> <var> <var-name>minlength</var-name> <var-value>3</var-value> </var> </field> </form> </formset> </form-validation> 4)ApplicationResources.properties
# Resources for parameter 'com.validator.struts.ApplicationResources' # Project P/validator err.minlength= err min < 3 err.maxlength= err max > 5 心得: validation 这是个难啃的骨头 要多多的接触
java package test;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document; import org.w3c.dom.Element;
import com.opensymphony.xwork2.ActionSupport;
public class TAction extends ActionSupport { private String xml1; public String getXml1() { return xml1; } public void setXml1(String xml1) { this.xml1 = xml1; } { try { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder();
// 创建 Document document = builder.newDocument(); Element root = document.createElement("root"); document.appendChild(root); Element name = document.createElement("name"); name.setAttribute("type", "ok"); name.appendChild(document.createTextNode("liu!k>a^i!@$^*><{}yi")); root.appendChild(name);
// 从数据库提取 // String xmlstr= "<beans><name>liu</name><pass>123</pass></beans>"; // builder.parse(new ByteArrayInputStream(str.getBytes()));
// save to mysql StringWriter output = new StringWriter(); TransformerFactory.newInstance().newTransformer().transform( new DOMSource(document), new StreamResult(output)); //System.out.println(output.toString());
// 对内展现 XPathFactory factoryXpah = XPathFactory.newInstance(); XPath xpath = factoryXpah.newXPath(); XPathExpression expr = xpath.compile("//name"); System.out.println(expr.evaluate(document)); expr = xpath.compile("//name/@type"); //System.out.println(expr.evaluate(document));
// 对jsp jstl xml // 参考 http://www.java2s.com/Code/Java/JSP/XML.htm
this.xml1 = output.toString().replaceAll("<\\?.*\\?>", ""); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { System.out.println(new TAction().getXml1()); }
}
jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jstl/xml_rt" prefix="x"%> <%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <c:import url="http://127.0.0.1:38080/ljw_svn2/test/data.do" var="webXml" /> <x:parse xml="${webXml}" var="doc" /> <x:out select="$doc//name"/><br /> </body> </html> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jstl/xml_rt" prefix="x"%> <%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body>
<c:set var="basepath" value="<%=request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/" %>"></c:set> <c:import url="${basepath}/infoPublishing.do?c=showXmlData&bid=63" var="webXml" /> <x:parse xml="${webXml}" var="doc" /> 类型:<x:out select="$doc//typeFlag"/><br /> qq:<x:out select="$doc//qq"/><br /> msn:<x:out select="$doc//msn"/><br />
</body> </html>
问题:
jsp 的简化与 统一性 解决: EL 标签 jsp.页面 <%@ taglib prefix="fn" uri="/WEB-INF/fn.tld" %> <%@ taglib prefix="c" uri="/WEB-INF/c-1_0-rt.tld" %> <%@ taglib prefix="x" uri="/WEB-INF/x-1_0-rt.tld" %> <%@ page isELIgnored="false" %> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'MyJsp.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <c:set var="url"><%=basePath%>/xml</c:set> <c:import var="xmlDoc" url="${url}"/> <x:parse xml="${xmlDoc}" var="doc" />
//xml解析 <c:set var="bookName" ><x:out select="$doc/xml-body/books/book[@id='1']"/></c:set>
//xml 定位 ${fn:substring(bookName,"0", fn:length(bookName)-2 ) }<br> //字符substring
<x:forEach var="item" select="$doc/xml-body/books/book" > //迭带 <x:out select="$item" /><br> </x:forEach> </body> </html>
结果得到是: book1_goog book1_google book2_baidu book3_tiancai/xml 路径是 package Servlet;
import java.io.IOException; import java.io.PrintWriter;
import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
public class XmlServlet extends HttpServlet { /** * */ private static final String CONTENT_TYPE = "text/html; charset=GBK"; public void init() throws ServletException{} public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,IOException{ PrintWriter out = response.getWriter(); response.setContentType(CONTENT_TYPE); response.setCharacterEncoding("GBK"); out.print("<?xml version='1.0' encoding='UTF-8'?>"); out.print("<xml-body>"); out.print("<name>RW</name>"); out.print("<passWord>123456</passWord>"); out.print("<age>28</age>"); out.print("<books>"); out.print("<book id='1'>book1_google</book>"); //jsp 定位得到的 字符 out.print("<book id='2'>book2_baidu</book>"); out.print("<book id='3'>book3_tiancai</book>"); out.print("</books>"); out.print("</xml-body>"); } public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException,IOException{ doGet(request,response); } }
心得:写EL心情 就是好
JSP 自定义标签 1. <my:list pass="${pass}"/>pass 的建立是(1)tld文件加 <attribute>(2).java加 private String pass gget() gset() 2. 要有 Body .java 就继承 BodyTagSupport 不要就 TagSupport 3. doStartTag() 中 输出是 pageContext.getOut().print("hello."+this.pass); 4. doAfterBody() 中 输出是 BodyContent bc = super.getBodyContent(); String bStr = bc.getString(); // body 中的 string bc.getEnclosingWriter().print(...); // out to jsp 5. <my:list pass="liukaiyi"> <c:if test="${gg==null}"> //会先运行得到 String 再在 bc.getString()得到 String XX </c:if> </my:list> 4. .java 中 通过是 doStartTag() return SKIP_BODY 跳向 doEndTag() return EVAL_BODY_INCLUDE 跳过主体 doBodyContent() return EVAL_BODY_BUFFERED 调用doInitBody() 5. .java 中 doAfterBody() return SKIP_BODY 跳出循环 到 doEndTag() return EVAL_BODY_AGAIN 再次 doAfterBody() 6. .java 中 doEndTag() retrun EVAL_PAGE 继续剩余 return SKIP_PAGE 跳出
Tag 自定义标签 1. <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %> 倒入 并在 tags 文件中 建 XXX.tag 2. 使用 EG: <my:文件名 /> 3. <my:MyTag items="${name}" />在文件.tag中加入 <%@ attribute name="items"%> 并在 body中${items}就可以使用 4. body加标签 同 JSP 自定义标签 5 5. <my:MyTag items="d" > <jsp:attribute name="list"> //添加body模块 ..<>.. </jsp:attribute> </my:MyTag> 在 .tag 中 <%@ attribute name="list" fragment="true" required="true" %> 取得 <jsp:invoke fragment="list" /> 使用中的 String
我开个头 希望大家 也贡献些 :-)
摘要: 问题:
用户在 WEB 中输入 机车 人员 等项 页面会根据当前字符给出选择提示解决:scriptaculous javascript工具包的 Autocompleter.Local 与图对应代码:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->... 阅读全文
问题:
画页面 或 报表 的 图象问题 解决:用 通过xml画图 画笔wz_jsgraphics.js xml数据取得 prototype.js 画动作 Xmlgraphics.js (自己包装) 下载: http://www.blogjava.net/Files/Good-Game/Mywz_jsgraphics.rar 请放在 服务器上(tomcat) 并改 testLine.html页面上的 load( ul ) =>> ul ( xml 的取得地方 ) 请注意 : IE 5 支持不好 请用 火狐 或 IE6 图片 :
EG: 这展现了 画线 画图 到 画字的简单过程 <grabhics>
<line x1='0' y1='0' x2='40' y2='0' color='green' stroke='4' /> <line id='l1' x1='0' y1='0' x2='0' y2='200' color='darkblue' stroke='8' /> <rect x='20' y='20' w='40' h='70' color='hotpink' stroke='4' /> <rect id='r1' x='100' y='60' w='20' h='200' color='greenyellow' stroke='8' /> <fillRect x='50' y='60' w='40' h='70' color='darkolivegreen' stroke='2' /> <fillRect id='fr1' x='150' y='250' w='20' h='45' color='darkturquoise' stroke='1' /> <ellipse x='0' y='100' w='50' h='100' color='darkolivegreen' stroke='5' /> <ellipse id='e1' x='250' y='0' w='34' h='46' color='darkturquoise' stroke='7' /> <fillEllipse x='0' y='150' w='150' h='70' color='darkolivegreen' stroke='5' /> <fillEllipse id='fe1' x='250' y='20' w='84' h='48' color='gray' stroke='7' /> <fillArc x='32' y='124' w='130' h='170' start='0' end='190' color='red' /> <fillArc id='fa1' x='200' y='300' w='40' h='20' start='0' end='300' color='red' />
<polygon xs='32,80,23,7,64' ys='124,2,42,24,6' color='darkolivegreen' /> <polygon id='pp1' xs='32,4,2' ys='124,3,51' color='darkolivegreen' />
<fillPolygon xs='10,85,93,60' ys='50,10,105,87' color='00aaaa' /> <fillPolygon id='adfh' xs='80,126,-30,-60' ys='0,130,40,100' color='00aaaa' />
<image x='200' y='300' w='50' h='50' url='../image/test.bmp' /> <image id='ima' x='300' y='300' w='50' h='50' url='../image/test.bmp' />
<string font='arial' size='15' style='Font.ITALIC_BOLD' str='刘凯毅' x='300' y='400' color='red' /> <string id='strr' font='arial' size='20' style='Font.ITALIC_BOLD' str='万岁' x='310' y='420' />
</grabhics>
简单页面 : 给出 div 的 id (位置 和 xml 的出处 就可以了)load() 方法 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script language="JavaScript" src='../lib/prototype/wz_jsgraphics.js' ></script> <script language="JavaScript" src="../lib/prototype/prototype.js"></script> <script language="JavaScript" src="../js/test.js" ></script> <script language="JavaScript" src="../js/Xmlgraphics.js" ></script> </head> <body onload='load( "http://127.0.0.1:8000/Mywz_jsgraphics/xml/graphics.xml" )'> <div id="myCanvas" style="position:relative;height:250px;width:100%;"> <input type='button' onclick='tt()' /> </div> </body> </html>
<script> function tt(){ var uu = 'strr' var g2 = getGdom(uu) ; getValue(uu).clear(); } </script>
1. 开始 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TEST</title> <script type="text/javascript" src="wz_jsgraphics.js"></script> </head> <body> <div id="myCanvas" style="position:relative;height:250px;width:100%;"></div> </body> </html>
<script type="text/javascript"> <!--
var jg = new jsGraphics("myCanvas");
jg.setColor("#00aaaa"); jg.fillArc(100,200,200,150,0,20);
jg.paint();
//--> </script>
07-11-9 由于我对hibernate理解的深入,在次我来终结下这篇文章的不足的地方(好多人在拍砖哈) 对复杂的逻辑这样开和关太冒失了。 在普通的逻辑方法中 session都叠加的用上2次以上 这就要对一级缓冲的管理。事物的使用也是一样。
下载: http://www.blogjava.net/Files/Good-Game/hibernateUtil.rar简单的继承包 : 继承 DBManage 类 把 数据包装类 管理 ( 填充 , set 等 ) 后就直接放到里 insert , update , delete 方法中 填充可看看这个,很有实用价值 ----> ( 当 Form -> Bean 或 Bean ->Bean ) 例子很简单但想法表明 继承 DBSelect 类 为 select 这只是 把 Query 给出 简单用法 是 Query qu = dao.getQueryBegin( " HQL " ); qu.add ..... List li = dao.getQuertyEnd( qu ); 扩展: Criteria cr , SQLQuery , 等等 把她包装成 各个 dao 中 不是 很 偷懒 : ) Eg : extendsDBBasic 类 public List select(String id,String time){
List list = new ArrayList(); Query qu = getQueryBegin("HSQL"); //继承带来的好处 .add.......... List list = getQuertyEnd(qu); //继承结束 return list; } 缺点: 最好不要static 在一时间点上 此类不能支持多线程 basicBegin basicEnd 方法 ( 我找不到好的方法 要的话来个 连接池什么的 大家讨论西西吧!! ) sess 为全局的 session 要是 写成 baseicBegin 返回的话 感觉下面的还有很多要写 什么 close 啊... sess 也是缺点的所在 当然大家 有什么想法 改下 或自己来个 小包装 我只是 抛砖引玉 private Map transmap = new HashMap();
protected Session basicBegin(){ Session sess = SessionManager.currentSession(); try { transmap.put( sess, sess.beginTransaction() ); }catch(Exception e){System.out.println(e);} return sess ; } protected void basicEnd(Session sess){ try { ((Transaction)transmap.remove(sess)).commit(); }catch(Exception e){System.out.println(e);} finally{ sess = null ; SessionManager.closeSession(); } } 心得: 多包装多快乐
|