墻頭草的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方法(111484)
2.?Quartz的cron表達式(84569)
3.?No result defined for action(66315)
4.?Java NIO框架Mina、Netty、Grizzly介紹與對比(43724)
5.?JAVA中 return的用法(31505)
評論排行榜
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
墻頭草
閱讀(822)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright ©2025 墻頭草
人人游戲網
軟件開發網
貨運專家
主站蜘蛛池模板:
欧美男同gv免费网站观看
|
国产一卡2卡3卡4卡2021免费观看
|
国产无遮挡又黄又爽免费视频
|
亚洲免费电影网站
|
日韩国产免费一区二区三区
|
国产精品亚洲精品青青青
|
成全视频免费高清
|
亚洲AV日韩AV天堂久久
|
色欲A∨无码蜜臀AV免费播
|
亚洲精品无码国产
|
你是我的城池营垒免费看
|
国产亚洲婷婷香蕉久久精品
|
av永久免费网站在线观看
|
亚洲AV无码国产丝袜在线观看
|
久章草在线精品视频免费观看
|
亚洲精品无码久久毛片波多野吉衣
|
亚欧人成精品免费观看
|
亚洲第一区二区快射影院
|
成人永久免费福利视频网站
|
免费的黄网站男人的天堂
|
国产精品久久久亚洲
|
99无码人妻一区二区三区免费
|
亚洲精品无码人妻无码
|
亚洲精品在线视频
|
99re在线这里只有精品免费
|
亚洲一区电影在线观看
|
亚洲国产中文字幕在线观看
|
华人在线精品免费观看
|
丁香婷婷亚洲六月综合色
|
亚洲AV永久无码精品一区二区国产
|
99麻豆久久久国产精品免费
|
成人毛片免费视频
|
一个人看的www视频免费在线观看
|
亚洲AV无码乱码在线观看富二代
|
亚洲欧洲高清有无
|
亚洲av再在线观看
|
亚洲第一网站免费视频
|
美女尿口扒开图片免费
|
亚洲不卡中文字幕无码
|
免费三级毛片电影片
|
一区在线免费观看
|