楼主: omencathay

[jsp]常见问题集锦索引贴

[复制链接]
论坛徽章:
0
31#
发表于 2005-6-14 09:25 | 只看该作者
对我很有帮助,辛苦啦

使用道具 举报

回复
论坛徽章:
0
32#
发表于 2005-6-15 08:46 | 只看该作者
对我很有帮助,辛苦啦

使用道具 举报

回复
论坛徽章:
33
2011新春纪念徽章
日期:2011-01-25 15:41:012012新春纪念徽章
日期:2012-02-13 15:11:52ITPUB 11周年纪念徽章
日期:2012-10-10 13:11:14兰博基尼
日期:2013-11-04 12:55:50马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:11:52
33#
 楼主| 发表于 2005-6-20 23:11 | 只看该作者

Java_struts 入门快速手册

----by omencathay
Struts
简介
1、        Struts基于MVC模式 Model(Bean) ,View(jsp文件), Control (Action类,ActionForm类)
2、        开发准备
struts   http://jakarta.apache.org/struts
jdk1.2版本以上 http://java.sun.com/j2se
Xerces XML parser   http://xml.apache.org/xerces-j
下载struts后,解压zip文件到一个临时目录;然后拷贝struts.jar, jakarta-oro.jar, jdbc2_0-stdext.jar和common*.jar文件到你所应用struts的WEB-INF/lib目录下;拷贝struts*.tld文件和*.dtd文件到WEB-INF目录下,确定该才提到的所有的jar包都在web应用服务器的 classpath环境变量上设置。
3、        配置 (两个xml文件:web.xml, struts-config.xml)
配置web.xml,第一件事情就是注册组件action servlet,<servlet> .. </servlet>标签封装了整个struts 框架的应用程序
<!-- Action Servlet Configuration -->
1  <servlet>
2    <servlet-name>action</servlet-name>
3    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
4    <init-param>
5      <param-name>application</param-name>
6      <param-value>myApp.properties.ApplicationResources</param-value>
7    </init-param>
8    <init-param>
9      <param-name>config</param-name>
10      <param-value>/WEB-INF/struts-config.xml</param-value>
11    </init-param>
12    </servlet>
13 <!-- Action Servlet Mapping -->
14  <servlet-mapping>
15    <servlet-name>action</servlet-name>
16    <url-pattern>*.do</url-pattern>
17  </servlet-mapping>
18  <!-- Application Tag Library Descriptor -->
19  <taglib>
20    <taglib-uri>/WEB-INF/lib/app.tld</taglib-uri>
21    <taglib-location>/WEB-INF/lib/app.tld</taglib-location>
22  </taglib>
23  <!-- Struts Tag Library Descriptor -->
24  <taglib>
25    <taglib-uri>/WEB-INF/lib/struts.tld</taglib-uri>
26    <taglib-location>/WEB-INF/lib/struts.tld</taglib-location>
27  </taglib>
28  <!-- Struts Tag Library Descriptors -->
29  <taglib>
30    <taglib-uri>/WEB-INF/lib/struts-bean.tld</taglib-uri>
31    <taglib-location>/WEB-INF/lib/struts-bean.tld</taglib-location>
32  </taglib>
33  <taglib>
34    <taglib-uri>/WEB-INF/lib/struts-form.tld</taglib-uri>
35    <taglib-location>/WEB-INF/lib/struts-form.tld</taglib-location>
36  </taglib>
37  <taglib>
38    <taglib-uri>/WEB-INF/lib/struts-logic.tld</taglib-uri>
39    <taglib-location>/WEB-INF/lib/struts-logic.tld</taglib-location>
40  </taglib>
41  <taglib>
42    <taglib-uri>/WEB-INF/lib/struts-template.tld</taglib-uri>
43    <taglib-location>/WEB-INF/lib/struts-template.tld</taglib-location>
44  </taglib>

struts-config.xml文件
1 <?xml version="1.0" encoding="ISO-8859-1" ?>
2 <!DOCTYPE struts-config PUBLIC
3  "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
4  "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
5 <struts-config>
6 <data-sources>
7        <data-source key = "myDatabase">
8          <set-property property="autoCommit" value="false"/>
9                           
10          <set-property property="description"
11                           value=" Login Validation Database"/>
12          <set-property property="driverClass"
13                           value="org.postgresql.Driver"/>
14          <set-property property="maxCount"
15                           value="4"/>
16          <set-property property="minCount"
17                            value="2"/>
18           <set-property property="user"
19                           value="myusername"/>
20          <set-property property="password"
21                           value="mypassword"/>
22          <set-property property="url" value="jdbcostgresql://localhost/myAppDatabase"/>
23                           
24        </data-source>
25      </data-sources>
26 <!-- ========== Form Bean Definitions ========================== -->
27 <form-beans>
28  <!-- Logon form bean -->
29  <form-bean      name="login"
30                  type="myApp.FormBeans.LoginForm"/>
31     <!-- Order List -->
32  <form-bean      name="orderlist"
33                  type="myApp.FormBeans.OrderForm"/>
34 </form-beans>
35 <!-- ========== Global Forward Definitions ===================== -->
36  <global-forwards>
37    <forward   name="login"                path="/login.jsp"/>
38  </global-forwards>
39 <!-- ========== Action Mapping Definitions ===================== -->
40  <action-mappings>
41 <!-- Process a user logon -->
42    <action    path="/login"
43               type="myApp.action.LoginExec"
44               name="login"
45               validate = "true"
46              scope="session"
47              input="/login.jsp">
48   <forward name="success"       path="/secondpage.jsp"/>
49   <forward name="listorder"     path="/orderlistentry.do"/>
50   <forward name="killSession"   path="/SystemError.html"/>
51    </action>
52 <!-- Process a user logoff -->
53    <action    path="/logout"
54               type="myApp.action.LogoutExec">
55      <forward name="success"   path="/logout.jsp"/>
56    </action>
57 <!-- Process an order list -->
58    <action path="/orderlistentry"
59            type="myApp.action.OrderListExec"
60            name="orderlist"
61           scope="session"
62           input="/orderlistentry.jsp">
63      <forward name="success" path="/orderlistdisp.jsp"/>
64      <forward name="killSession" path="/SystemError.html"/>
65      <forward name="loginAgain" path="/login.jsp"/>
66      <forward name="selectSalesArea" path="/salesAreas.jsp"/>
67    </action>
68  </action-mappings>
69 </struts-config>

注:最重要的部分是action-mappings 部分
  <action-mappings>
  每个<action>元素定义了特定的功能与相关联的动作类, 大多数action元素至少包括以下三个部分。
Path-----应用程序映射的路径
Type-----需要的完整的包和类
Name-----action应用的<form-bean>元素的名称

<forward>标签告诉struts框架将要跳转到哪个jsp页面;
<data-sources>标签给出数据源属性;


4、        struts核心标签库示例
1. Html:form
属性:onsubmit

onsubmit属性得到的是:表单提交时的javaScript事件句柄
用法:
(1).
Onsubmit 和 html:submit配合使用,javaScript函数返回true或false

<html:form action=”” onsubmit=”return javaScriptFunction();”>

<html:submit onclick=” javaScriptFunction();”/>
配合使用
在javaScriptFunction(){
}中加入return true和return false
html:from 根据返回的true或者false决定是否提交
等同于
(2)。
     使用Html:button 要在javaScript函数中加入form.submit();
<html:form action=””>
       <html:button onclick=” javaScriptFunction();”/>
form.submit();决定表单的提交

2. Html:text
Html:text是输入框,可以修改数据做为property的值


如果要修改的属性在bean中有get\set方法,可以写为
<html:text name="listInfoFormBean" property="invoiceCode"/>

如果要修改的属性在某一个VO里,在VO里对这一属性有get\set方法,在bean里对这一VO有get\set方法,可以写为:
<html:text name="listInfoFormBean" property="tbInvStoresVO.invoiceCode"/>

3. Bean:write
Bean:write与html:text用法相似。只是bean:write输出的数据是readonly的

这一点可以在html:text中加入属性 readonly=”true”来实现

4. Html:select
   <html:select property="invoicePurchaseCode" name=”beanname”>
    <option value="0">----</option>
    <option value="1">验旧供新</option>
    <option value="2">交旧供新</option>
    <option value="3">批量供应</option>
    </html:select>
name::bean的名称。如果没有设置,将适用于这个内嵌表单相关的formbean的名字
property:表单提交是送回的请求参数的名字,也是用来确定哪个属性被选中的bean的属性的名字
value:用来表明需要被选中的选项

怎么生成一个select:
option.options = new(value, lablename)

5. logic:iterate
   logic:iterate的两个用法
1. 在javaScript中初始化数组数据
//声明数组
var invoiceWordCodeArray = new Array();

//构造函数
function invoiceWordCode(invoiceCode,invoiceWordCode){
this.invoiceCode = invoiceCode;
this.invoiceWordCode = invoiceWordCode;
}

//初始化数据
<logic:iterate id="item2" name="listInfoFormBean" property="wordCodeList" indexId="i">
invoiceWordCodeArray[<bean:write name="i"/>] =
new invoiceWordCode(
'<bean:write name="item2" property="invoiceCode"/>',
'<bean:write name="item2" property="invoiceWordCode"/>');
</logic:iterate>

2.在页面上循环显示一个集合中的数据
<logic:iterate indexId="idx" id="sampleBean" name="sampleList">
<tr>
<td align="center" style="padding:1px 4px 0px 5px"></td><td width="150">
<bean:write property="id" name="sampleBean"/></td><td width="150">
<bean:write property="content" name="sampleBean"/></td><td width="150">
<bean:write property="creator" name="sampleBean"/></td>
</tr>
</logic-el:iterate>
id:页面作用域bean的名称,集合的别名
name:formbean的名字,它包含property
property:需要循环的集合的名字
logic:iterate:需要在formbean中对集合中的VO有get\set方法
indexed=”true”:每次重复完成后集合当前的索引

使用道具 举报

回复
论坛徽章:
1
开发板块每日发贴之星
日期:2005-06-24 01:02:15
34#
发表于 2005-6-23 20:34 | 只看该作者
顶一下,收藏

使用道具 举报

回复
论坛徽章:
0
35#
发表于 2005-6-24 14:24 | 只看该作者
挺全的,谢谢拉!

使用道具 举报

回复
论坛徽章:
0
36#
发表于 2005-6-28 11:06 | 只看该作者
好....先收藏.有空再来品一品

使用道具 举报

回复
论坛徽章:
0
37#
发表于 2005-7-3 10:20 | 只看该作者

如何解决mysql问题

请问如何解决mysql问题

使用道具 举报

回复
论坛徽章:
0
38#
发表于 2005-7-4 20:35 | 只看该作者
duo 谢   楼主   写的很好的

使用道具 举报

回复
论坛徽章:
0
39#
发表于 2005-7-13 01:04 | 只看该作者
不顶的………………,你还是顶一下吧

使用道具 举报

回复
论坛徽章:
2
开发板块每日发贴之星
日期:2005-07-30 01:02:19授权会员
日期:2005-10-30 17:05:33
40#
发表于 2005-7-21 14:30 | 只看该作者
不行的,提示你  <data-source key = "myDatabase">tomcat启动的时候提示attribute"type" is required must be specified for element type "data-source"

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表