Struts2 Validation Framework Tutorial with Exampleby Viral Patel · December 24, 2009 Welcome to Part-3 of 7-part series of tutorials where we will go through different practical aspects of Struts2 Framework. In the last part we Created a Basic Struts2 Application from Scratch. I strongly recommend you to go through the previous articles in case you are new to Struts2. In this article we will learn
When creating web applications it is generally a good idea to not allow exceptions thrown in various places of your application to be propagated to the end-user, since you donât want to give users information on your application which they donât need and which they might be able to use against you. An exception in a Struts2 application can be thrown from 2 places: From your action class From your
Struts2ã«ã¦æä¾ããã¦ããããã©ã«ãã®ä¾å¤ãã³ãã©ã ã¤ã³ã¿ã¼ã»ãã¿ã®å é ã«ç»é²ããã¦ãããã¨ãããä¸çªæåã¨æå¾ã«ç¨¼åãã¾ãã®ã§ ãã®ã¤ã³ã¿ã¼ã»ãã¿ã«ä¾å¤ãç»é²ãããã¨ã§ãä¾å¤ã«ããç»é¢ã®ãã³ããªã³ã°ãè¡ãã¾ãã ãã®å¢çã¯å®è£ é å(Actionã¯ã©ã¹ï½)ã¨ãStruts2層ã®é Actionã¯ã©ã¹ã®ã¢ã¯ã·ã§ã³ã¡ã½ãããæ¨æºã§Exceptionãã¹ãã¼ããããã«ãªã£ã¦ããã®ã§ Actionã¯ã©ã¹å é¨ã§çºçããä½ããã®ä¾å¤ã¯ããã®ã¾ã¾Actionã¯ã©ã¹ãéãæãã¦ã ExceptionInterceptorã¸ä¼æãã¾ãã ããã§ãã³ããªã³ã°ããªãå ´åã¯ããã®ã¾ã¾ä¾å¤ç»é¢ã¸ã¨é·ç§»ãã¾ãã ãµã³ãã«è¨å®ä¾ <struts> <package name="default" extends="struts-default" abstract="true"> ⦠<globa
å¹³æ25å¹´ï¼æ15æ¥ãä¸æ£ã¢ã¯ã»ã¹ã«ããã客æ§æ å ±æµåºã®å¯è½æ§ã«é¢ãããç¥ããã¨ãè©«ã³ãã§ãå ±åãããã¾ããå½ç¤¾ãªã³ã©ã¤ã³ã·ã§ããã«å¯¾ããä¸æ£ã¢ã¯ã»ã¹ï¼ä»¥ä¸ããæ¬ä»¶ä¸æ£ã¢ã¯ã»ã¹ãã¨ããã¾ããï¼ã«ãããã客æ§ãã¯ããã¨ããçæ§ã«å¤å¤§ãªããè¿·æããã³ãå¿é ãããããã¾ãããã¨ãæ·±ããè©«ã³ç³ãä¸ãã¾ãã å½ç¤¾ã¯ãäºæ¡çºè¦ç´å¾ãããé次ææ°æ å ±ããå ±åããã¦ããã ãã¦ããã¾ãããããã®åº¦ãå½ç¤¾ãå°é調æ»æ©é¢ããã³æ å ±æ¼ããäºæ 調æ»å§å¡ä¼ã«ããæ¬ä»¶ä¸æ£ã¢ã¯ã»ã¹ã«é¢ããä¸é£ã®èª¿æ»ãçµäºãããã¾ããã®ã§ãä¸è¨ã®ã¨ãããå ±åããã¦ããã ãã¾ãã ãªããæ¬ä»¶ä¸æ£ã¢ã¯ã»ã¹ã«é¢ããã客æ§ã¸ã®ã対å¿ããã³åçºé²æ¢ã«å¯¾ããåãçµã¿ã«ã¤ãã¦ã¯å¼ãç¶ãè¡ã£ã¦ã¾ããã¾ãããæ¬ä»¶ä¸æ£ã¢ã¯ã»ã¹ã«å¯¾ãã調æ»çµæã«ã¤ãã¾ãã¦ã¯ãç¹æ®µã®å ±åäºé ãçºçããªãéããä¸è¨ããã£ã¦æçµå ±åã¨ããã¦ããã ãã¾ãã å½ç¤¾ã¯ãèªç¤¾ãéå¶ãããJ
使ãæ¹ã¨è¨ã£ã¦ããTokenInterceptorã¨æ®ã©å¤ãããªãã ã§ãä½ãéãã®ãã¨ããã¨ãé常ãã©ã³ã¶ã¯ã·ã§ã³Tokenã§Tokenãéãå ´åã¨ã©ã¼ã¡ãã»ã¼ã¸ãä»ã®ç»é¢ã表示ããäºã«ãªãããããã ã¨èª¤ã£ã¦ï¼éãã¹ããããæ¶è²»è ã«ã¯ã¨ã©ã¼ç»é¢ã表示ãããå®äºç»é¢ã«ãç®ã«ãããäºãã§ããªãã ããã§ãTokenSessionStoreInterceptorã®ç»å ´ã¨ãªãããã¡ãã¯Actionçµæã®ValueStackã®å 容ãTokenå¦çå¾ã«Sessionã«è¨é²ãã¦ãããï¼éãã¹ãã®ãªã¯ã¨ã¹ããæ¥ãã¨ãã«SessionããValueStackãåæ§ç¯ãã¦ãããããå ã ã®ãªã¯ã¨ã¹ãã®ããã«çµæç»é¢ã表示ãã¦ãããã ããã§ãï¼éãã¹ãããã¦ãã¾ã£ãæ¶è²»è ãç®åºåº¦ãå®äºç»é¢ãè¦ããã¨ãã§ãã表示ããã¦ããåãåããçªå·ãã¡ã¢ãããã¨ãã§ããã ã¡ãã£ã¨TIPSï¼ValueStackãSessi
Actionã¯ã©ã¹ã®ããããã¨ãActionã¯ã©ã¹ã®è¨å®ã«é¢ããConventionãã©ã°ã¤ã³ã®ã¾ã¨ããæ¸ãã¦ãªãã£ãã®ã§ãããã§ããä¸åº¦ã¾ã¨ãã¾ãã 1. Actionã¯ã©ã¹ã§ããã¹ãã㨠HTTPãªã¯ã¨ã¹ãï½ã¬ã¹ãã³ã¹ãè¿ãã ããªãã°ã以ä¸ã®ï¼ã¤ã ãã§ãã ã»ç»é¢(View)ããã®ãªã¯ã¨ã¹ããåãåãã¡ã½ãããpublicã§ä½æãã ã»Actionã¯ã©ã¹ã§ã®å¦çãçµãã£ãå¾ã«è¡¨ç¤ºããç»é¢(View)ï¼ã¬ã¹ãã³ã¹ã決å®ããresultãè¿ã ã¬ã¹ãã³ã¹ã¯JSPã ãã§ã¯ãªããVelocityãªã©ã®ãã³ãã¬ã¼ããããã¦ã³ãã¼ããããã¹ããå¯è½ã§ãPDFãJSONå½¢å¼ããã©ã°ã¤ã³å°å ¥ã§å¯è½ã§ããã¬ã¹ãã³ã¹ã®å½¢å¼ãå¿ ãæå®ãã¾ããï¼æå®ããªãå ´åã¯JSPã¸ãã©ã¯ã¼ãï¼ ãã以å¤ã®å®è£ ããã¨ãã°ãã¼ã¿ãã¼ã¹ãå©ç¨ããActionãä½ãå ´åã¯ãããã«å¿ããã³ã¼ãã追å ãã¦ãããã¨ã«ãªãã¾ãã
ã¯ããã« æ¬ç¨¿ã§ã¯Struts 2ã«ã¦JSONã¬ã¹ãã³ã¹ãç°¡åã«æ±ããããã«ãªãStruts 2 JSONãã©ã°ã¤ã³ãç´¹ä»ãã¾ãã JSONã«ã¤ã㦠JSONã¯JavaScript Object Notationã®ç¥ç§°ã§ããJavaScriptã«ã¦ãªãã¸ã§ã¯ããè¨è¿°ããéã«ã使ããã表è¨æ³ã§ãAJAXãå©ç¨ããWEBã¢ããªã±ã¼ã·ã§ã³ã§ã¯é åã®ãã¼ã¿ãæ軽ã«æ±ãããã¨ããããç¾å¨ãã£ã¨ãå©ç¨ããã¦ããæ¹å¼ã§ãã詳細ãªä»æ§ã«ã¤ãã¦ã¯JSONã®ç´¹ä»ãåç §ãã ããã 対象èªè Struts 2ã®Webã¢ããªã±ã¼ã·ã§ã³éçºã«èå³ããæ¹ å¿ è¦ãªç°å¢ æä½åä½ç°å¢ã¯æ¬¡ã®ã¨ããã§ãã Java SE 5 Struts 2.2.1ãåä½ããç°å¢ Tomcat 5.5.x / 6.0.x Struts 2 JSONãã©ã°ã¤ã³ã¨ã¯ Struts 2 JSONãã©ã°ã¤ã³ã¯ãStruts 2ã®ã¢ããªã±ã¼ã·ã§ã³ã§ç°¡å
CodeZineç·¨éé¨ã§ã¯ãç¾å ´ã§æ´»èºãããããããã¼ãã¹ã¿ã¼ã«ããããã®ã«ã³ãã¡ã¬ã³ã¹ãDevelopers Summitãããã¨ã³ã¸ãã¢ã®çããã¾ããã¼ã¹ãããããã®ã¤ãã³ããDevelopers Boostããªã©ããã¾ãã¾ãªã«ã³ãã¡ã¬ã³ã¹ãä¼ç»ã»éå¶ãã¦ãã¾ãã
Interceptorå¦ç ç°¡åã«è¨ãã°ã¢ã¯ã·ã§ã³ãèµ·ããåã«å²ãè¾¼ã¾ããå¦çã®äºã§ãã ç°¡åãªãµã³ãã«ãåå¼·ãã¦ãä½ã£ãã®ã§ãã¡ã¢ãã¾ãã Struts2.1.8.1ã§ãã ã¨ããããInterceptorå¦çãè¨è¿°ãã¾ãã âLoginInterceptor.java ---------------------------------------------- package interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; @SuppressWarnings("serial") public class LoginInterceptor extends AbstractIntercep
æ¬é£è¼ã§ã¯ããªã¼ãã³ã½ã¼ã¹ã®ãµã¼ããµã¤ãJavaåãWebã¢ããªã±ã¼ã·ã§ã³ã»ãã¬ã¼ã ã¯ã¼ã¯ãStruts 2ãããå®éã«åä½ããã¢ããªã±ã¼ã·ã§ã³ã¨å ±ã«è§£èª¬ãã¦ããã¾ãã第6åç®ã®æ¬ç¨¿ã¯ãå é ãªãªã¼ã¹ããããã¼ã¸ã§ã³2.1.6ã«ã¤ãã¦ã¨ãZero Configurationï¼ã¼ãã»ã³ã³ãã£ã®ã¥ã¬ã¼ã·ã§ã³ï¼ã¨å¼ã°ãããXMLè¨å®ãã¡ã¤ã«ãç¨ããªãã§ã¢ããªã±ã¼ã·ã§ã³ãæ§ç¯ããæ¹æ³ã«ã¤ãã¦èª¬æãããã¨ã«ãã¾ãã ã¯ããã« ãApache Strutsãï¼ä»¥ä¸ãStrutsï¼ã¨ã¯ããµã¼ããµã¤ãJavaéçºã®ããã¡ã¯ãã¹ã¿ã³ãã¼ãã¨ãã¦ãã¾ãã«ãæåãªããªã¼ãã³ã½ã¼ã¹ã®Webã¢ããªã±ã¼ã·ã§ã³ã»ãã¬ã¼ã ã¯ã¼ã¯ã§ããæ¬é£è¼ã§ã¯ããã®Strutsã®æ¬¡ä¸ä»£ãã¼ã¸ã§ã³ã§ããStruts 2ããå®éã«åä½ããã¢ããªã±ã¼ã·ã§ã³ã¨å ±ã«è§£èª¬ãã¦ããã¾ãã 第6åç®ã®æ¬ç¨¿ã¯ãå é ãªãªã¼ã¹ããããã¼ã¸ã§ã³2.1.6ã«ã¤ãã¦
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}