https://www.google.com.tw/search?q=portlet:actionURL+render&ie=utf-8&oe=utf-8&gws_rd=cr&ei=zM5wWdfvCsS_0QTa5KuYBw
跨頁面
PortSession
經典 Portlet Spring MVC 範例
Platform门户组件 程序设计指南
儲存前頁面資料
2017年7月20日 星期四
2017年2月18日 星期六
Spring_Struts2_Hebernat_資源配置
此章節是把練習常用的 maven 集合在一起
如果要使用
起把不必要的去除
web.xml
spring mvc 不適用
只需看 pom.xml 和 web.xml 擺放位置
歡迎轉載,請註明出處。
如果要使用
起把不必要的去除
<dependencies>
<!-- Spring core & mvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<!-- Servlet Spec -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<!-- Json -->
<!-- <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId>
<version>2.8.5</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId> <version>2.8.5</version>
</dependency> -->
<dependency><!-- jackson -->
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.4.2</version>
</dependency>
<!-- 添加JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Struts2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.8</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.1.8</version>
</dependency>
</dependencies>
web.xml
spring mvc 不適用
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Struts 2 Web Application</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>*.action</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
只需看 pom.xml 和 web.xml 擺放位置
歡迎轉載,請註明出處。
2017年2月10日 星期五
JAVA-Spring MVC 入門初體驗 ( 四 )_實作
20190609 整理多餘的程式碼
前面我們有提到基本簡介
前面我們有提到基本簡介
此篇就在介紹實作的部分,此篇尚未講到 Bean 部分
我們實作有以下步驟:
1 . 匯入有需要的 Jar
2 . 設定 web.xml
3 . 設定 projectName-servlet.xml
4 . 攥寫 Controller
5 . 攥寫 Jsp
我們實作有以下步驟:
1 . 匯入有需要的 Jar
2 . 設定 web.xml
3 . 設定 projectName-servlet.xml
4 . 攥寫 Controller
5 . 攥寫 Jsp
將這次此專案需要的 Jar 添加至 pom.xml 內
說明 : pom 的功能比較常用於匯入網路上的 Jar
為何不直接下載?是否能確定你我他都是載同一個版本??
說明 : pom 的功能比較常用於匯入網路上的 Jar
為何不直接下載?是否能確定你我他都是載同一個版本??
<dependencies>
<!-- Spring core & mvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
</dependencies>
設定 web.xml
說明:
專案的進入點,所以要在這邊設定或過濾 Url 所要做的動作
HelloWeb-servlet.xml (這是預設格式,如需指定檔案名稱,需要另外寫設定)
設定掃描註記之對象及頁面管理規範
將 Spring MVC 的設定檔注入設定
Jsp 頁面
其實這有點像我們之前用過的 Srvlet 只是把它用註記方法取代
說明:
@Controller 必須標注在開頭
並且將對應的 Uri 放置在對應方法的上方
我們執行剛剛所創建出來的專案 : http://localhost:8080/FirstSpring/hello
注意 : 請務必依照對應的位置擺放
歡迎轉載,請註明出處。
說明:
專案的進入點,所以要在這邊設定或過濾 Url 所要做的動作
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
HelloWeb-servlet.xml (這是預設格式,如需指定檔案名稱,需要另外寫設定)
設定掃描註記之對象及頁面管理規範
將 Spring MVC 的設定檔注入設定
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.brian.prduct.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Jsp 頁面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head>
<body>
${key}
</body>
</html>
其實這有點像我們之前用過的 Srvlet 只是把它用註記方法取代
說明:
@Controller 必須標注在開頭
並且將對應的 Uri 放置在對應方法的上方
package com.brian.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET )
public String search(ModelMap modelMap) {
modelMap.put("key", "hello");
// 返回與要顯示的頁面名稱
return "hello";
}
}
我們執行剛剛所創建出來的專案 : http://localhost:8080/FirstSpring/hello
注意 : 請務必依照對應的位置擺放
歡迎轉載,請註明出處。
2017年1月22日 星期日
JAVA-Spring MVC 入門初體驗 ( 三 )_註記
上一篇提到:JAVA-Spring MVC 入門初體驗 ( 二 )_說明
此篇提到的是:註記
不僅簡化許多功能
更能重於開發
以下整理出比較常用幾點
此篇提到的是:註記
不僅簡化許多功能
更能重於開發
以下整理出比較常用幾點
| @Controllel | 將此 Controller 註冊到 Spring MVC 內 |
| @RequestMapping | 指定處理哪些 URL 請求 |
| @RequestBody | 可讀取 Request 數據 |
| @ResponeseBody | 可返回 ResponeseBody 參數 |
| @ModelAttribute | 讀取模型化數據 |
| @RequestParam | 讀取請求參數的變數 |
| @PathVariable | |
| @ExceptionHandler | |
| @ControllerAdvice |
2017年1月21日 星期六
JAVA-Spring MVC 入門初體驗 ( 二 )_說明
這章節我們延續上一章節:JAVA-Spring MVC 入門初體驗 ( 一 )_流程
我們既然這樣分類
一定有他的用意
以下說明可以配合上章節的流程圖
首先
Web.xml
1 . 最主要是用來攔截、過濾 URL 帶來的資料
2 . 遇到以上狀態要就往指定目錄 ( mvc-config.xml ) 處理
3 . 定義初始歡迎頁面、如果遇到 404 狀態要顯示的頁面
Mvc-config.xml
1 . 整合所有專案資源,包括:Controller、JSP...等。
2 . MVC 註記功能設定
Controller.java
1 . 配置 URL 所要做的動作,比如:讀取輸入資料並反饋...等
View.jsp
1 . 將一些預載設定放置的靜態網頁
將以上做一的簡單的整理
1 . Web.xml 先收到請求,然後交給 Mvc-config.xml 處理
2 . 接下來都是由 Mvc-config.xml 進行中控
3 . 並且在 Controller.java 設定的內容
4 . 如果有調用到 Jsp ,則會去指定目錄下找指定的檔案
參考資料: Spring MVC 配置文件 web.xml文件详解
歡迎轉載,請註明出處。
我們既然這樣分類
一定有他的用意
以下說明可以配合上章節的流程圖
首先
Web.xml
1 . 最主要是用來攔截、過濾 URL 帶來的資料
2 . 遇到以上狀態要就往指定目錄 ( mvc-config.xml ) 處理
3 . 定義初始歡迎頁面、如果遇到 404 狀態要顯示的頁面
Mvc-config.xml
1 . 整合所有專案資源,包括:Controller、JSP...等。
2 . MVC 註記功能設定
Controller.java
1 . 配置 URL 所要做的動作,比如:讀取輸入資料並反饋...等
View.jsp
1 . 將一些預載設定放置的靜態網頁
將以上做一的簡單的整理
1 . Web.xml 先收到請求,然後交給 Mvc-config.xml 處理
2 . 接下來都是由 Mvc-config.xml 進行中控
3 . 並且在 Controller.java 設定的內容
4 . 如果有調用到 Jsp ,則會去指定目錄下找指定的檔案
參考資料: Spring MVC 配置文件 web.xml文件详解
歡迎轉載,請註明出處。
JAVA-Spring MVC 入門初體驗 ( 一 )_流程
Spring mvc 是一種架構
能夠更確實分類您要的應用
我們就拿生活中的例子比喻 :
衣物就歸放於衣櫥內
鞋子就歸放於鞋櫃內
工具就歸放於工具箱內
所以在寫程式時,都一定有它的功能
我們就依照他的功能去擺放對應的位子
如果我們需要啥麼物件、資料...等
我們只需要做呼叫的動作
所有的事情都能幫我們解決了
首先我們先來分析專案底下基本常用架構
以下分析圖表為這篇要講的主題
所以一次不會講解太多
避免一下子介紹太多導致無法吸收
所以依照上方圖表我們自己創立一個全新專案
1 . 記得添加 Pom.xml 檔案( 導入要的 Jar 超級方便 )
通常接下來只需點選完成
不需要做額外的設定
2 . 添加 Controller.java 到 src 底下
目前不需要任何的內容
( 如果不清楚怎麼放,可以參考下圖 )
3 . 在 WebContent/WEB-INF/
添加 web.xml & mvc-config.xml & jsp folder
方法如下
這樣是不是如我們第一章圖表一樣的流程~
參考資料 : 史上最全最强SpringMVC详细示例实战教程
參考資料 : 使用Spring JDBCTemplate简化JDBC的操作
能夠更確實分類您要的應用
我們就拿生活中的例子比喻 :
衣物就歸放於衣櫥內
鞋子就歸放於鞋櫃內
工具就歸放於工具箱內
所以在寫程式時,都一定有它的功能
我們就依照他的功能去擺放對應的位子
如果我們需要啥麼物件、資料...等
我們只需要做呼叫的動作
所有的事情都能幫我們解決了
首先我們先來分析專案底下基本常用架構
以下分析圖表為這篇要講的主題
所以一次不會講解太多
避免一下子介紹太多導致無法吸收
所以依照上方圖表我們自己創立一個全新專案
1 . 記得添加 Pom.xml 檔案( 導入要的 Jar 超級方便 )
通常接下來只需點選完成
不需要做額外的設定
2 . 添加 Controller.java 到 src 底下
目前不需要任何的內容
( 如果不清楚怎麼放,可以參考下圖 )
3 . 在 WebContent/WEB-INF/
添加 web.xml & mvc-config.xml & jsp folder
方法如下
這樣是不是如我們第一章圖表一樣的流程~
參考資料 : 史上最全最强SpringMVC详细示例实战教程
參考資料 : 使用Spring JDBCTemplate简化JDBC的操作
2017年1月14日 星期六
JAVA-JSP 頁面資料利用 Ajax 傳送至 Controller
How send data to controller by ajax ?
如果在做網頁開發時
如果在做網頁開發時
我們一定聽過 Ajax 這好用的工具
更是前後端保持暢通的橋樑
但是我們要如何將資料整理後並將資料傳送至 Controller
首先 , 使用的方法有 :
1 . 傳統字串資料傳送
2 . JSON
一 . 傳統字串資料傳送
先在 Jsp 內匯入 JQuery 套件
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
並且在 Ajax 的 data 放置參數
格式為 :
最後在 HelloController.java 接收從 Jsp 傳來的參數
結果如下 :
query
1969
John
參考資料:Spring mvc系列六之 ajax运用(基于json格式)
參考資料:SpringMVC注解@RequestParam全面解析
參考資料:jQuery send string as POST parameters
參考資料:Ajax传值与接收值
歡迎轉載 , 請註明出處 .
格式為 :
"key1=value1&key2=value2......"
中間分隔用 & 串接$.ajax({
type : "post",
url : "http://localhost:8080/MyProject/query",
data: "id=1969&name=John", // 資料是用 & 做串接
success : function(response) {
alert('Success');
},
error : function() {
alert('fail');
}
});
最後在 HelloController.java 接收從 Jsp 傳來的參數
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@RequestMapping(value = "/query") // 對應的連結
@ResponseBody // 有回應
public String query(@RequestParam(value="id") Integer id,
@RequestParam(value="name") String name) {
// 上方欄位說明
// RequestParam 代表回應的參數
// value 代表對應的 Key
// 最後宣告參數型別
System.out.println("query");
System.out.println("" + id);
System.out.println("" + name);
return "searchUser";
}
}
結果如下 :
query
1969
John
參考資料:Spring mvc系列六之 ajax运用(基于json格式)
參考資料:SpringMVC注解@RequestParam全面解析
參考資料:jQuery send string as POST parameters
參考資料:Ajax传值与接收值
歡迎轉載 , 請註明出處 .
訂閱:
文章 (Atom)






