标签:style blog http color io os ar 使用 java
最近又重拾 web 程式,才讓我發現,原來 struts 又進化了! 提供了不少 jQuery tag,可以很方便的做出漂亮的操作介面! 說明如下:
裡面的 beans-config.xml 及 datasource.properties 在這裡還用不到,這是我在下一篇要用 spring 及 mybatis 存取資料庫時才會用到的。
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.16.3</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.3.16.3</version> </dependency> <dependency> <groupId>com.jgeppert.struts2.jquery</groupId> <artifactId>struts2-jquery-plugin</artifactId> <version>3.7.1</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>2.3.16.3</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-json-plugin</artifactId> <version>2.3.16.3</version> </dependency>
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Struts2</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <constant name="struts.convention.action.packages" value="idv.steven.demo.action"/> <constant name="struts.convention.default.parent.package" value="json-default"/> <constant name="struts.custom.i18n.resources" value="messages" /> <!-- Settings for CKEditor Image Upload --> <constant name="struts.ckeditor.allowUploads" value="true" /> <!-- default is false --> <constant name="struts.ckeditor.allowedFileExtensions" value="jpg,jpeg,png" /> <constant name="sstruts.ckeditor.uploadFolder" value="/imageUploads" /> <!-- include file="showcase.xml" / --> </struts>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>首頁</title> <sj:head/> </head> <body> <s:url var="remoteurl1" action="calendar"/> <s:url var="remoteurl2" action="stock"/> <sj:tabbedpanel id="remotetabs" selectedTab="0" show="true" hide="‘fade‘" collapsible="true" sortable="true"> <sj:tab id="tab1" href="%{remoteurl1}" label="日曆"/> <sj:tab id="tab2" href="%{remoteurl2}" label="股價"/> </sj:tabbedpanel> </body> </html>
package idv.steven.demo.action; import java.util.Date; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.opensymphony.xwork2.ActionSupport; public class CalendarAction extends ActionSupport { private static final long serialVersionUID = 1840098879054587910L; final static Logger logger = LoggerFactory.getLogger(CalendarAction.class); private String selectedDate; //action method @Action(value = "/calendar", results = { @Result(location = "/jsp/calendar.jsp", name = "success") }) public String calendar() throws Exception { return SUCCESS; } @Action(value = "/showDate", results = { @Result(location = "/jsp/showDate.jsp", name = "success") }) public String showDate() throws Exception { return SUCCESS; } //getter & setter method public String getSelectedDate() { return selectedDate; } public void setSelectedDate(String selectedDate) { this.selectedDate = selectedDate; } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>日曆</title> <sj:head jqueryui="true"/> </head> <body> <s:form id="form" theme="xhtml"> <sj:datepicker id="selectedDate" name="selectedDate" label="請選擇日期" displayFormat="yy/mm/dd" /> <sj:submit href="showDate" targets="result" value="送出" indicator="indicator" button="true" /> </s:form> <sj:div id="result" /> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> ${selectedDate}
标签:style blog http color io os ar 使用 java
原文地址:http://www.cnblogs.com/stevwn/p/4033512.html