天天看點

Struts2系列之二:頁面傳值

[url=http://czj4451.iteye.com/blog/1498582]Struts2系列之一:建構struts2項目[/url]

[url=http://czj4451.iteye.com/blog/2116355]Struts2系列之三:注解式Action[/url]

以登入為例:

[size=medium]1. 頁面檔案[/size]

在webapp下建立login.jsp:

其中上下文可以寫成:<%=request.getContextPath()%>

在WEB-INF下建立main.jsp:

[size=medium]2. Action類[/size]

LoginAction.java:

Struts2會将請求表單中的屬性值自動填充到Action的對應屬性中,可以為結果頁面使用。

[size=medium]3. 配置檔案:[/size]

在struts.xml中加入:

[size=medium]4. 測試[/size]

啟動web工程,在浏覽器輸入:http://localhost:8080/mystruts2/login.jsp,輸入使用者名(John)和密碼,送出後顯示輸入的使用者名:

Welcome, John