(1)部署lib庫中文件Struts+ibatis,共6個。
(2)配置struts2中的web.xml,目的是讓Struts2來解釋web應用。內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter> <!--定義filter名稱,制定filter使用的類 -->
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern><!--定義filtemapping指定搜索路徑為根路徑開始-->
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
(3)配置Struts2的Struts.xml文件,目的是建立struts2中邏輯調用機制。-----------------------改
內容如下:===============================需要修改
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="yzth" namespace="/" extends="struts-default">
<action name="hello" class="org.lxh.struts2.demo.HelloAction">
<result name="success">
/hello.jsp
</result>
<result name="error">
/error.jsp
</result>
</action>
</package>
</struts>
(4)配置Ibatis中的各個關鍵環節
POJO類的建立 *** 用于存儲ORMapping映射后的數據記錄,只包含get 和set 方法
com.mydomain.jata中的
Account.xml *** 最重要的ORMapping文件,存儲了對數據訪問的各種映射的SQL操作。
SqlMapConfig.xml *** 存儲連接數據的方法,配置數據連接池。
(5)設計調用界面
index.jsp==>hello.action==>account.class(應該從hello.action中調用ormapping)==>struts.xml==>hello.jsp
(5.1)index.jsp使用S:標記傳值給hello.action
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<form action="hello.action" method="post">
根據ID進行查詢:<input type="text" name="msg">
<input type="submit" value="提交">
</form>
(5.2)hello.action使用Msg接收id后,調用account進行查詢。
===========================================================================
這個過程沒搞清楚,準備找1個struts2+ibatis的開源項目研究一下再繼續。。。。