action怎麼寫
- 綜合知識
- 關注:1.48W次
/**
* 登入
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward doLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Users users = new Users();
users.setUserName(request.getParameter("userName"));
users.setPassword(request.getParameter("password"));
users = userBiz.userLogin(users);
if (users != null) {
request.getSession().setAttribute("users", users);
return mapping.findForward("index");
}
return mapping.findForward("login");
}
2. java中的action怎麼寫public interface Actionextends ActionListener
Action 介面提供 ActionListener 介面的一個有用擴充套件,以便若干控制元件訪問相同的功能。
除了 ActionListener 介面定義的 actionPerformed
方法之外,此介面還允許應用程式在一個位置定義:
描述函式的一個或多個文字字串。這些字串可用於顯示按鈕的立體文字、在選單項中設定文字等等。
描述函式的一個或多個圖示。這些圖示可用於選單控制元件中的影象,或者用於更復雜使用者介面中的合成項。
功能的啟用/禁用狀態。應用程式可以禁用實現此介面的函式,而不必分別禁用選單項和工具欄按鈕。所有為偵聽狀態更改而註冊為偵聽器的元件都將禁止為該項生成事件,並相應地修改顯示。
可以將此介面新增到現有類中,或者用它建立一個介面卡(通常通過子類化 AbstractAction 來實現)。然後可以將
Action 物件新增到多個可感知 Action 的容器中,並連線到可容納
Action 的元件。然後可以通過呼叫 Action 物件的 setEnabled
方法立刻啟用或取消啟用 GUI 控制元件。
注意,Action 實現在儲存方面的開銷比典型的 ActionListener
要高,但後者不具有集中控制功能和廣播屬性更改的優點。因此,應該注意只在需要這些優點的地方使用 Action,在別處使用
ActionListener 即可。
支援 Action 的 Swing 元件
許多 Swing 的元件都具有 Action 屬性。在元件上設定 Action
時,會發生以下幾種情況:
Action 被作為 ActionListener 新增到元件。
元件配置自身的某些屬性以匹配 Action。
元件在 Action 上安裝 PropertyChangeListener,這樣元件可更改其屬性以反映 Action 屬性中的更改。
3. jsp action怎麼寫 很簡單<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/action</url-pattern>
</servlet-mapping>
表單中的action的寫法:/action;和<url-pattern>;標籤中的值一致,myeclipse中生成的JSP頁面開頭都有String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<head>;標籤內有<base href="<%=basePath%>">
如果<head>;中沒有上述內容,action寫成<%=basePath%>/action最保險
4. action裡該寫什麼給你個例項參考一下,細節另外處理:
<form name="form2" action="">
跳轉到:<input type="text" name="page" size="2"/>
<input type="button" name="button" value="go" onclick="check(document.form2)"/><;!--這裡不使用submit型別-->
</form>
<script>
function check(formobj){
formobj.action="menu_index_top.jsp?t_type="+formobj.page.value;
formobj.submit();
}
</script>
或者:
<form name="form2" action=""method="post" onSubmit="return check(this)"><;!--這裡應指出提交方式否則可能出現錯誤-->
跳轉到:<input type="text" name="page" size="2"/>
<input type="submit" name="submit" value="go"/>
</form>
<script>
function check(formobj){
formobj.action="menu_index_top.jsp?t_type="+formobj.page.value;
return true;
}
</script>
======================================================
不指出,位址列可能出現&submit=go
5. form表單提交裡面的action怎麼寫你說的是action層獲取form表單提交上來的資料嗎?
提供一種方法:
控制層相關程式碼:request.getParameter("userName");
(注:userName是from表單中name屬性的值)
jsp頁面中form表單相關程式碼:
6. 關於struts2的 action怎麼寫額 看不懂你說的哦
不過struts2中的action最普遍要繼承ActionSupport這個類,而你們老師繼承ServletRequestAware類反正我們用過,然後就是定義實體類,和藉口的方法。在spring中注入
struts2中的方法以public String +方法名(){return "111";}來進行操作 return 裡面的字串要和你struts2配置中的那個<result name="111">;/頁面的位置</result>;中的name屬性相同,你在登入頁面的form中呼叫你寫的“方法名”就進入方法中如果成功返回“111”就會進入你所設定的頁面位置。
7. 關於struts2的 action怎麼寫,呵呵,這個要看你的Struts-config.xml裡面是怎麼配置的了,你可以在配置檔案裡面配置Action的引數,name="這裡是你要訪問的Action的名字,也就是你在from表單裡面的" class="這裡是你的Action的路徑" method="這個是你在Action裡面的你要訪問的方法名字" 。
比如: 那麼from裡面就是:
- 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/zonghezhishi/wr8e34.html