1.struts2.0çå·¥ä½åçï¼
2.struts2如何接收多个参数
struts2.0çå·¥ä½åçï¼
客æ·ç«¯ååºä¸ä¸ªè¯·æ±ï¼æå¡å¨ç«¯StrutsPreparedAndExceuteFilteræ¥æ¶è¯·æ±ãå¦æ该请æ±æ¯ä¸ä¸ªä»¥ .action ç»å°¾è¯·æ±ï¼åStruts2å°è¯·æ±è½¬åè³ç¸åºçActionï¼è¿è¡æ°æ®ç±»å转æ¢ï¼å¦ææ°æ®ç±»å转æ¢åºéï¼åè¿åå° input æå®çç»æ页é¢ã
å¦ææ°æ®ç±»å转æ¢æ²¡æåºéï¼åè°ç¨setXX æ¹æ³è¿è¡è®¾å¼ï¼å¦æ使ç¨äºvalidate()éªè¯æ¹æ³ï¼æè æ¯ä½¿ç¨äºéªè¯æ¡æ¶ï¼ï¼åè¿è¡ç¸åºçéªè¯ã
å¦æéªè¯åºéï¼åå° input æå®çç»æ页é¢ã
å¦æ没æ使ç¨éªè¯ï¼æè éªè¯æ²¡æåºéï¼åæ§è¡ executeï¼ï¼ æ¹æ³ï¼è¿åå°ç¸åºç页é¢ã
æ©å±èµæï¼
Struts2æµç¨æ³¨è§£
å½Web容å¨æ¶å°è¯·æ±ï¼HttpServletRequestï¼å®å°è¯·æ±ä¼ éç»ä¸ä¸ªæ åççè¿æ»¤é¾å æ¬ï¼ActionContextCleanUpï¼è¿æ»¤å¨ã
ç»è¿Other filters(SiteMesh ,源码etc)ï¼éè¦è°ç¨FilterDispatcheræ ¸å¿æ§å¶å¨ï¼ç¶åå®è°ç¨ActionMapperç¡®å®è¯·æ±åªä¸ªActionï¼ActionMapperè¿åä¸ä¸ªæ¶éAction详ç»ä¿¡æ¯çActionMaping对象ã
FilterDispatcherå°æ§å¶æå§æ´¾ç»ActionProxy,ActionProxyè°ç¨é 置管ç(ConfigurationManager) ä»é ç½®æ件ä¸è¯»åé 置信æ¯(struts.xml)ï¼ç¶åå建ActionInvocation对象ã
ActionInvocationå¨è°ç¨Actionä¹åä¼ä¾æ¬¡çè°ç¨æç¨é ç½®æ¦æªå¨ï¼Interceptor Nï¼ä¸æ¦æ§è¡ç»æè¿åç»æå符串ActionInvocationè´è´£æ¥æ¾ç»æå符串对åºç(Resultï¼ç¶åæ§è¡è¿ä¸ªResult Resultä¼è°ç¨ä¸äºæ¨¡çï¼JSPï¼æ¥åç°é¡µé¢ã
æ¦æªå¨(Interceptor N)ä¼å被æ§è¡ï¼é¡ºåºåActionæ§è¡ä¹åç¸åï¼æåååº(HttpServletResponse)被è¿åå¨web.xmlä¸é ç½®çé£äºè¿æ»¤å¨åæ ¸å¿æ§å¶å¨ï¼FilterDispatcherï¼ã
åèèµææ¥æºï¼ç¾åº¦ç¾ç§-Struts 2
struts2如何接收多个参数
Struts2的核心是FilterDispatcher,它会处理我们的请求,不用考虑太多,源码仿腾讯充值源码它使用了代理模式,源码php 流媒体源码action里面接收form里面的源码达尔文流媒体源码值,记得form与action里面的OO对象一致,或者采用对象.属性方式进行代码编写 form代码: 1. <form action="resgist" method="post"> 账号:<input type="text" name="username" />
工号:<input type="text" name="userpassword"/>
<input type="submit" value=" 注 册 " />
</form> 2. <form action="resgist" method="post"> 账号:<input type="text" name="user.name" />
工号:<input type="text" name="user.password"/>
<input type="submit" value=" 注 册 " />
</form> action代码:1. private String username; //username对象,源码泡妞秘籍网站源码与form一致
private String userpassword;//userpassword对象与form一致
public String getUsername() {
return username;
} /
*** @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
} /
*** @return the userpassword
*/
public String getUserpassword() {
return userpassword;
} /
*** @param userpassword the userpassword to set
*/
public void setUserpassword(String userpassword) {
this.userpassword = userpassword;
}2.User实体类里面有name、源码黑暗之光源码password属性private User user; //user对象,源码与form一致
/
*** @return the user
*/
public User getUser() {
return user;
} /
*** @param user the user to set
*/
public void setUser(User user) {
this.user = user;
} 3.获取表单值存入session:if("admin".equalsIgnoreCase(user.getName().trim()&&"".equals(user.getPassword))){ ActionContext.getContext().getSession().put("admin",源码 user.getName());} 其他更详细的请阅读《Struts2权威指南》或者《WebWork in Action》