Oracle JDeveloper 10g Struts Creation Date: May 28, 2004 Last Update: Aug 19, 2004 Version 1.0.1
... 1... 2... 2... 2... 4... 4... 5 HTML/JSP/Servlet... 7 JSP... 7 Servlet... 11 Struts... 15 Struts... 15 Struts... 16... 17... 25 FormBean LoginForm... 28... 29... 31 Action LoginAction... 33 Welcome... 34 oracleonline.jsp... 35... 36... 37 Oracle JDeveloper Struts 1
Oracle JDeveloper Web Servlet Struts JSP/Servlet JDeveloper JSP/Servlet Struts JDeveloper JDeveloper 1. Oracle JDeveloper Struts 2
2. OK アプリケーション 名 : SampleTest ディレクトリ 名 : (デフォルトのまま) アプリケーション パッケージの 接 頭 辞 :(なし) アプリケーション テンプレート: NoTemplate [All Technologies]? Web Servlet JSP Struts Java GUI Swing/AWT No Template Oracle JDeveloper Struts 3
Project 1. 2. General - Projects OK Oracle JDeveloper Struts 4
3. OK プロジェクト 名 : StrutsDemo ディレクトリ 名 : (デフォルトのまま) T T Java T HTML/JSP T J2EE T etc Oracle JDeveloper Struts 5
1. 2. OK デフォルト パッケージ: sample.test.strutsdemo Oracle JDeveloper Struts 6
HTML/JSP/Servlet HTML JSP Servlet HTML/JSP HTML JSP & JSP 1. Project Oracle JDeveloper Struts 7
2. カテゴリ: Web Tier - JavaServer Pages (JSP) を 選 択 項 目 : JSP ページ を 選 択 3. JSP ファイル 名 : ディレクトリ 名 : testpage.jsp (デフォルトのまま) 4. testpage.jsp web.xml Oracle JDeveloper Struts 8
5. (i) (ii) HTML (iii) HTML Table x x x x Oracle JDeveloper Struts 9
POINT: 6. 7. JSP testpage.jsp Oracle JDeveloper Struts 10
Servlet 1. Web Tier - Servlets HTTP 2. HTTP 3. クラス: パッケージ: コンテンツ タイプを 生 成 : メソッドの 実 装 : TestServlet (デフォルトのまま) (デフォルトのまま) doget() にチェック Oracle JDeveloper Struts 11
4. 2 Name: name Type: String Variable: username 5. 3 Oracle JDeveloper Struts 12
6. TestServlet.java TestSersvlet.java TestServlet.java package mypackage; import javax.servlet.*; import javax.servlet.http.*; import java.io.printwriter; import java.io.ioexception; public class TestServlet extends HttpServlet private static final String CONTENT_TYPE = "text/html; charset=windows-31j"; public void init(servletconfig config) throws ServletException super.init(config); public void doget( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException String username = ""; try username = request.getparameter("name"); catch(exception e) e.printstacktrace(); response.setcontenttype(content_type); PrintWriter out = response.getwriter(); out.println("<html>"); out.println("<head><title>testservlet</title></head>"); out.println("<body>"); Oracle JDeveloper Struts 13
out.println("<p>the servlet has received a GET. This is the reply.</p>"); out.println("</body></html>"); out.close(); 8. 9. Servlet TestServlet.java Oracle JDeveloper Struts 14
Struts Struts Struts login.jsp FormBean LoginForm Action LoginAction Welcome welcome.jsp oracleonline.jsp Oracle JDeveloper Struts 15
Struts Struts Struts & Struts struts-config.xml Struts T T Struts T T Oracle JDeveloper Struts 16
1. StrutsDemo 2. Web Tier - Struts Struts Controller OK 3. struts-config.xml ApplicationResources.properties Oracle JDeveloper Struts 17
struts-config.xml Struts Struts Page Flow 4. Struts Page Flow 5. /page1 /login 6. /login ページ 名 : /login.jsp Oracle JDeveloper Struts 18
7. login.jsp login 8. Struts Struts Page Flow 9. /action1 /loginaction 10. /loginaction Struts Action 名 前 : LoginAction パッケージ: (デフォルトのまま) 拡 張 対 象 : (デフォルトのまま) 11. LoginAction.java LoginAction.java Oracle JDeveloper Struts 19
package sample.test.strutsdemo; import org.apache.struts.action.action; import org.apache.struts.action.actionform; import org.apache.struts.action.actionmapping; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.struts.action.actionforward; import org.apache.struts.action.actionerror; import org.apache.struts.action.actionerrors; import java.io.ioexception; import javax.servlet.servletexception; public class LoginAction extends Action /** * This is the main action called from the Struts framework. * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * @return * @throws java.io.ioexception * @throws javax.servlet.servletexception */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException return mapping.findforward("success"); Action 12. Struts Struts Page Flow & 13. /page1 /welcome 14. /welcome welcome Oracle JDeveloper Struts 20
ページ 名 : /welcome.jsp 15. welcome.jsp welcome 16. Struts Struts Page Flow & 17. /page1 /oracleonline 18. /oracleonline ページ 名 : /oracleonline.jsp 19. oracleonline.jsp oracleonline Oracle JDeveloper Struts 21
20. Struts Struts Page Flow /login /loginaction POINT: JSP login.jsp JSP 21. Struts Page Flow /loginaction /welcome 22. Struts Page Flow /loginaction /oracleonline Oracle JDeveloper Struts 22
23. /logiaction /oracleonline forward1 oracle 24. FormBean /loginaction Bean 25. Struts Form Bean login FormBean 名 前 : LoginForm パッケージ: (デフォルトのまま) 拡 張 対 象 : (デフォルトのまま) フォーム Bean 名 : LoginForm Oracle JDeveloper Struts 23
26. LoginForm.java LoginForm.java package sample.test.strutsdemo; import org.apache.struts.action.actionform; import org.apache.struts.action.actionerrors; import org.apache.struts.action.actionerror; import org.apache.struts.action.actionmapping; import javax.servlet.http.httpservletrequest; public class LoginForm extends ActionForm /** * Reset all properties to their default values. * @param mapping The ActionMapping used to select this instance. * @param request The HTTP Request we are processing. */ public void reset(actionmapping mapping, HttpServletRequest request) super.reset(mapping, request); /** * Validate all properties to their default values. * @param mapping The ActionMapping used to select this instance. * @param request The HTTP Request we are processing. * @return ActionErrors A list of all errors found. */ public ActionErrors validate( ActionMapping mapping, HttpServletRequest request) return super.validate(mapping, request); Struts struts-config.xml 27. Struts Oracle JDeveloper Struts 24
FormBean Bean 28. Struts Struts Struts-Html ActionForm Bean 1. login.jsp login.jsp Struts login.jsp 2. Struts Html Oracle JDeveloper Struts 25
3. & <html:form> JSP Tag Editor action: loginaction.do POINT:<html:form> action struts-config.xml JDeveloper struts-config.xml 4. Form 5. Form 6. Struts Html & <html:text> JSP Tag Editor property: username Oracle JDeveloper Struts 26
HINT: Form 7. Struts Html <html:password> JSP Tag Editor property: password Oracle JDeveloper Struts 27
8. & 9. action Struts Html 10. Submit JSP Tag Editor 11. FormBean LoginForm ActionForm Bean JSP T setter/getter ActionForm Bean Action T validate username password username password null Oracle JDeveloper Struts 28
1. LoginForm.java LoginForm.java 2. 3. username OK フィールド 名 : username フィールド 型 : java.lang.string スコープ: private アクセッサ: get メソッド set メソッド 両 方 にチェック Oracle JDeveloper Struts 29
4. 5. password OK フィールド 名 : password フィールド 型 : java.lang.string スコープ: private アクセッサ: get メソッド set メソッド 両 方 にチェック 6. 7. private String username; private String password; public String getusername() return username; public void setusername(string username) this.username = username; public String getpassword() return password; public void setpassword(string password) this.password = password; Oracle JDeveloper Struts 30
8. validate public ActionErrors validate(actionmapping mapping, HttpServletRequest request) ActionErrors errors=new ActionErrors(); if ((username==null) (username.length()<1) (password==null) (password.length()<1)) errors.add("username",new ActionError("error.login")); return errors; コード テンプレート - Oracle JDeveloper Struts 31
コード テンプレートの 使 い 方 1. 2. Ctrl + Enter public ActionErrors validate(act ife return super.validate(mapping public ActionErrors validate(act if () else return super.validate(mapping 9. LoginForm.java 10. validate struts-config.xml struts-config.xml struts-config.xml Action Mappings /loginaction /loginaction input: /login.do Oracle JDeveloper Struts 32
11. ApplicationResources.properties error.login=login ERROR Unicode Native2Ascii JDeveloper Native2Ascii 12. login.jsp login.jsp Struts Html & 13. Action LoginAction Action execute ActionForm Bean 1. LoginAction.java LoginAction.java 2. execute LoginForm password oracle OralceOnline oracle Welcome Oracle JDeveloper Struts 33
LoginForm loginform=(loginform)form; String password=loginform.getpassword(); if (password.equals("oracle")) return mapping.findforward("oracle"); return mapping.findforward("success"); mapping.fingforword( xxx ) struts-config.xml <forward> Struts 3. LoginAction.java Welcome XX Struts Bean ActionForm Bean 1. welcome.jsp welcome.jsp Struts welcome.jsp 2. 3. Struts Bean 4. LoginForm username Struts Bean <bean:write> JSP Tag Editor Oracle JDeveloper Struts 34
name LoginForm propery username POINT:name property Bean 5. 6. oracleonline.jsp OracleOnline 1. oracleonline.jsp oracleonline.jsp 2. Oracle JDeveloper Struts 35
JDeveloper J2EE 1. Struts /login 2. J2EE 3. oracle oracle welcome Oracle JDeveloper Struts 36
Oracle JDeveloper Struts JDeveloper Java XML J2EE JDeveloper Struts JDeveloper Oracle Application Development Framework Oracle ADF ADF Struts ADF Struts &! JavaBean EJB Web O-R Struts DB JSP Struts ADF Oracle JDeveloper Struts 37
Copyright 2004 Oracle Corporation Japan. All Rights Reserved. Oracle Oracle8 Oracle8i Oracle9i Net8 Oracle JDeveloper Struts 38