java学习第三天(ssh+extjs)
数据流从后台一直走到前台。。。。
1.dao层 (面向接口)
public ResultSet getacctname() {
Connection connection=OracleUtil.getConnection();
ResultSet acct=null;
if(connection!=null){
String sql = "select acctid as KMH,acctname as text,levelno as JC from t_fmaccount where levelno=1";
acct= OracleUtil.executeQuery(sql,connection);
}
OracleUtil.returnConnection(connection);
return acct;
}
2. service层
AccountDao acctdao=new AccountDaoImp();
public String getAccttree() throws SQLException {
java.sql.ResultSet rs=acctdao.getacctname();
Bm3DBF dbf = new Bm3DBF();
dbf=Bm3DBF.fromResultSet(rs);
dbf.AddField("ID",1,4,2,"");
dbf.AddField("CHECK",1,1,0,"");
Bm23Tree tree=new Bm23Tree(dbf,"总帐科目库","JC","ID","TEXT","KMH","CHECK");
return tree.getTreeData();
}
3.action层
private AccountManageImp acctmg;
public void setAcctmg(AccountManageImp acctmg) {
this.acctmg = acctmg;
}
public ActionForward acctname(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String jsonAcct = acctmg.getAccttree();
response.setContentType("text/json;charset=utf-8");
response.getWriter().println(jsonAcct);
return null;
}
4 前台ext.js
GeneralLedger = Ext.extend(SubPagePanelOne, {
initComponent : function() {
this.lefttree = new Ext.Bm3.tree({
connUrl : 'acctname.do',// 请求后台路径,此参数是必须的
rootVisible : false,
isStartMenu : true,
height:421,
autoScroll:true
});
当然能请求到数据,需要考配置文件了
5.web.xml
<web-app>
<display-name>Struts Blank Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
6. struts-config.xml
<struts-config>
<form-beans>
<form-bean name="AccountActionForm" type="com.sfzc.vo.actionform.AccountActionForm" />
</form-beans>
<action-mappings>
<action path="/acctname"
type="org.springframework.web.struts.DelegatingActionProxy" name="AccountActionForm"
scope="request" parameter="acctname">
</action>
</action-mappings>
<message-resources parameter="MessageResources"></message-resources>
</struts-config>
7.applicationcontext.xml
<beans>
<bean id="acctmg" class="com.sfzc.account.service.imp.AccountManageImp" />
<bean name="/acctname" class="com.sfzc.account.action.AccountAction">
<property name="acctmg" ref="acctmg" />
</bean>
</beans>