zk+jsp+servlet学习中的小例子

.jsp

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html xmlns:z="http://www.zkoss.org/2005/zk">
<head>
<title>zk+jsp+servlet使用</title>
 <zscript>
 void addEvent() {
   date_test.setValue(null); 
   try{
    txt_test.setValue(" ");
    txt_test.setValue("");
   }catch (WrongValueException e) {
    // TODO: handle exception
   }
   System.out.println("点击了重置");
   Messagebox.show("重置了");
   
  }
  <!-- 如何调用 javascript方法 -->
  void txtEvent(Component com){
   String str = txt_test.getValue();
   if(str!=" "){
    com.setAction("onclick:att()");
   }else{
    txt_test.setValue("");
   }
   
  }

 </zscript>
 <script type="text/javascript">
  function sendServlet(){
   alert("转到servlet中");
   document.all.fro.submit();
  }
 </script>
</head>
<body>
 <form name="fro" action="${pageContext.request.contextPath}/servlettest" method="post" xmlns:x="http://www.zkoss.org/2005/zul">
  <table >
   <tr>
    <td>username</td>
    <td><x:textbox id="txt_test" name="txt_test" constraint="no empty" /></td>
   </tr>
   <tr>
    <td>date</td>
    <td><x:datebox id="date_test" name="date_test"/></td>
   </tr>
   <tr>
<!--    <td><input name="up" type="button" value="到servlet中处理" z:onClick="txtEvent()"/></td>-->
    <td><x:button id="btn" label="到servlet中处理" focus="true" z:onClick="txtEvent(self)"/></td>
    <td><x:button  label="重置" z:onClick="addEvent()"/></td>
   </tr>
  </table>
 </form>
 
</body>
</html>

 

 

 

 

 

 

 

 

 

&&&&&&&&&&&&&&&&&&&&&&&&&

web.xml 添加以下

<filter>
  <filter-name>zkFilter</filter-name>
  <filter-class>org.zkoss.zk.ui.http.DHtmlLayoutFilter</filter-class>
  <init-param>
   <param-name>extension</param-name>
   <param-value>html</param-value> <!-- Use XHTML components as default. -->
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>zkFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>INCLUDE</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>ERROR</dispatcher>
 </filter-mapping>

你可能感兴趣的:(JavaScript,html,jsp,servlet,zk)