墻頭草的Java
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
posts - 241, comments - 116, trackbacks - 0
公告
<
2011年5月
>
日
一
二
三
四
五
六
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(6)
給我留言
查看公開留言
查看私人留言
隨筆分類
Apple蘋果(14)
Eclipse(3)
PHP(1)
Spring(4)
業界資訊(19)
引流(2)
隨筆檔案
2013年8月 (1)
2013年2月 (5)
2012年12月 (5)
2012年8月 (3)
2012年7月 (1)
2012年6月 (1)
2012年2月 (5)
2012年1月 (11)
2011年12月 (4)
2011年11月 (5)
2011年10月 (17)
2011年9月 (12)
2011年8月 (14)
2011年7月 (18)
2011年6月 (31)
2011年5月 (18)
2011年4月 (13)
2011年2月 (1)
2010年11月 (9)
2010年10月 (3)
2010年3月 (16)
2010年1月 (5)
2009年12月 (1)
2009年8月 (2)
2009年6月 (2)
2009年5月 (4)
2009年4月 (2)
2009年3月 (2)
2009年2月 (1)
2008年12月 (23)
2008年11月 (3)
友情鏈接
人人游戲網
貨運專家
軟件開發網
運費
搜索
最新評論
1.?re: springMVC后臺的值無法通過ModelAndView的addObject傳到前臺的解決方法
5一日一日
--讓他
2.?6666666
評論內容較長,點擊標題查看
--555
3.?6666666
<%out.print("fdfdsfdfdfdfdfdf");%>
--555
4.?re: JAVA中IP和整數相互轉化
IP地址數值應該用long吧,int溢出了
--楊小芳
5.?re: java靜態工廠方法
熱特瑞
--突然
閱讀排行榜
1.?java indexOf方法(111500)
2.?Quartz的cron表達式(84590)
3.?No result defined for action(66339)
4.?Java NIO框架Mina、Netty、Grizzly介紹與對比(43746)
5.?JAVA中 return的用法(31520)
評論排行榜
1.?No result defined for action(8)
2.?Quartz的cron表達式(6)
3.?java indexOf方法(6)
4.?JS禁用瀏覽器退格鍵(5)
5.?解決ActiveMQ中,Java與C++交互中文亂碼問題(5)
集成spring3
復制jar到WEB-INF/lib目錄:
復制,并添加到java build path:
Sql代碼
org.springframework.aop-3.1.0.M1.jar
org.springframework.asm-3.1.0.M1.jar
org.springframework.beans-3.1.0.M1.jar
org.springframework.context-3.1.0.M1.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.expression-3.1.0.M1.jar
org.springframework.web-3.1.0.M1.jar
spring包分類總結:
Sql代碼
============================================
spring3 lib:
core:
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
core depend lib:
org.springframework.asm-3.0.5.RELEASE.jar
web:
tld: spring.tld, spring-form.tld
org.springframework.web-3.0.5.RELEASE.jar
springMVC: org.springframework.web.servlet-3.0.5.RELEASE.jar
db:
org.springframework.orm-3.0.2.RELEASE.jar
org.springframework.
transaction-3.0.2.RELEASE.jar
org.springframework.jdbc-3.0.2.RELEASE.jar
aop:
org.springframework.aop-3.0.5.RELEASE.jar
depend
on:
aopalliance-1.0.jar
============================================
配置applicationContext.xml,并配置LoginAction的bean
普通bean配置,注意加上
scope="prototype"
注解方式配置:<context:component-scan base-package="org.skzr.demo"/>
applicationContext.xml:
Xml代碼
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
>
<bean id="loginAction" class="org.skzr.demo.action.LoginAction" scope="prototype"/>
<context:component-scan base-package="org.skzr.demo"/>
</beans>
添加注解到LoginAction.java,注意:
@Component("loginActionComponent") @Scope("prototype")
Java代碼
/**
* Copyright (c) 2010-2020 by wasion.com
* All rights reserved.
* @author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
* @date 2011-5-19 下午10:20:57
*/
package org.skzr.demo.action;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
/**
* 登錄檢測
* @author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
* @version 1.0.0
* @since JDK1.6
*/
@Component("loginActionComponent")
@Scope("prototype")
public class LoginAction extends ActionSupport {
private static final long serialVersionUID = 1L;
/** 用戶名 */
private String userName;
/** 密碼 */
private String password;
/**
* @return {@link #userName}
*/
public String getUserName() {
return userName;
}
/**
* @param userName {@link #userName}
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return {@link #password}
*/
public String getPassword() {
return password;
}
/**
* @param password {@link #password}
*/
public void setPassword(String password) {
this.password = password;
}
/**
* 登錄驗證
* @return 驗證后頁面視圖
*/
public String check() {
return "admin".equals(userName) ? "welcome" : "success";
}
}
修改web.xml
Xml代碼
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
>
<description>我愛編程</description>
<display-name>我愛編程</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>app.root</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>10000</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
啟動web查看后臺輸出是不是正常初始化spring
修改struts.xml的action從spring中獲取
Xml代碼
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"
>
<struts>
<package name="demo" extends="struts-default" namespace="/">
<action name="loginAction" class="org.skzr.demo.action.LoginAction">
<result>/WEB-INF/jsp/login.jsp</result>
<result name="welcome">/WEB-INF/jsp/welcome.jsp</result>
</action>
<!-- 來自spring配置的bean -->
<action name="loginActionSpring" class="loginAction">
<result>/WEB-INF/jsp/login.jsp</result>
<result name="welcome">/WEB-INF/jsp/welcome.jsp</result>
</action>
<!-- 來自spring注解配置的bean -->
<action name="loginActionSpringComponent" class="loginActionComponent">
<result>/WEB-INF/jsp/login.jsp</result>
<result name="welcome">/WEB-INF/jsp/welcome.jsp</result>
</action>
</package>
</struts>
哈哈struts運行不正常了,無法使用spring的:
修改struts.properties添加spring支持:
struts.objectFactory=spring
復制struts2-spring-plugin-2.2.3.jar到lib,并添加到java build path
重新運行系統即可正常登錄了。
新的登錄頁面login.jsp
Html代碼
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String
path = request.getContextPath();
String
basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%
>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>
<html>
<head>
<base href="<%=basePath%>">
<title>系統登錄:</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<center><h1>struts action</h1></center>
<form action="loginAction!check.do" method="post">
<table align="center">
<tr><td>用戶名:</td><td><input name="userName" value="${userName }"></td></tr>
<tr><td>密 碼:</td><td><input name="password" type="password"></td></tr>
<tr><td><input type="submit" value="登錄"></td><td><input type="reset" value="重置"></td></tr>
</table>
</form>
<center><h1>action配置在spring中的</h1></center>
<form action="loginActionSpring!check.do" method="post">
<table align="center">
<tr><td>用戶名:</td><td><input name="userName" value="${userName }"></td></tr>
<tr><td>密 碼:</td><td><input name="password" type="password"></td></tr>
<tr><td><input type="submit" value="登錄"></td><td><input type="reset" value="重置"></td></tr>
</table>
</form>
<center><h1>action配置在spring中的(注解方式配置)</h1></center>
<form action="loginActionSpringComponent!check.do" method="post">
<table align="center">
<tr><td>用戶名:</td><td><input name="userName" value="${userName }"></td></tr>
<tr><td>密 碼:</td><td><input name="password" type="password"></td></tr>
<tr><td><input type="submit" value="登錄"></td><td><input type="reset" value="重置"></td></tr>
</table>
</form>
</body>
</html>
posted on 2011-05-20 14:58
墻頭草
閱讀(825)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright ©2025 墻頭草
人人游戲網
軟件開發網
貨運專家
主站蜘蛛池模板:
亚洲一区二区三区乱码在线欧洲
|
久久精品亚洲综合
|
人妻18毛片a级毛片免费看
|
久久久久久曰本AV免费免费
|
婷婷亚洲久悠悠色悠在线播放
|
波霸在线精品视频免费观看
|
亚洲国产一区视频
|
亚洲女人影院想要爱
|
亚洲精品日韩一区二区小说
|
四虎成人免费影院网址
|
国产亚洲精品岁国产微拍精品
|
亚洲熟女www一区二区三区
|
久久综合AV免费观看
|
亚洲中文字幕无码久久2020
|
妞干网免费视频观看
|
在线91精品亚洲网站精品成人
|
十八禁无码免费网站
|
亚洲福利在线播放
|
亚洲最大福利视频
|
免费人成在线观看播放国产
|
日韩精品免费一线在线观看
|
成人福利免费视频
|
久久亚洲免费视频
|
亚洲视频在线观看免费视频
|
亚洲最大无码中文字幕
|
免费在线观看黄网
|
精品一区二区三区免费
|
亚洲精品午夜在线观看
|
99蜜桃在线观看免费视频网站
|
亚洲导航深夜福利
|
va亚洲va日韩不卡在线观看
|
亚洲中文字幕久久精品无码VA
|
免费无码又爽又刺激高潮的视频
|
亚洲熟女精品中文字幕
|
亚洲av区一区二区三
|
日本亚洲欧洲免费天堂午夜看片女人员
|
亚洲精品国产电影
|
2022久久国产精品免费热麻豆
|
亚洲色偷偷色噜噜狠狠99
|
伊人久久精品亚洲午夜
|
久久国产精品免费
|