隨筆:15 文章:206 評論:35 引用:0
fenglin
創新、創意、挑戰
C++博客
首頁
發新隨筆
發新文章
聯系
聚合
管理
Struts_路徑(Path)問題
Struts2中的路徑問題是根據action的路徑而不是jsp路徑來確定,所以
盡量
不要使用相對路徑
。
以下為實例:
index.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=ISO-8859-1"
>
<
title
>
Path
</
title
>
</
head
>
<
body
>
<
a
href
="path/path.action"
>
路徑問題說明
</
a
>
<
br
>
</
body
>
</
html
>
path.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=ISO-8859-1"
>
<
title
>
Struts2_Path
</
title
>
<%
String
path
=
request.getContextPath();
String
basePath
=
request.getScheme()
+
"
://
"
+
request.getServerName()
+
"
:
"
+
request.getServerPort()
+
path
+
"
/
"
;
%>
<
base
href
="<%=basePath%>"
/>
<!--
使用base標簽指定本頁面所有鏈接的參照路徑
-->
</
head
>
<
body
>
Struts2中的路徑問題是根據action的路徑而不是jsp路徑來確定,所以盡量不要使用相對路徑。
<
br
>
<
a
href
="index.jsp"
>
index.jsp
</
a
>
<
br
>
雖然可以用redirect方式解決,但redirect方式并非必要。
<
br
>
解決辦法非常簡單,統一使用絕對路徑。(在jsp中用request.getContextPath方式來獲取到webapp的路徑)
<
br
>
或者使用myeclipse經常用的,指定basePath
<
br
>
</
body
>
</
html
>
PathAction.java
package
com.bebig.struts2.path.action;
import
com.opensymphony.xwork2.ActionSupport;
public
class
PathAction
extends
ActionSupport
{
@Override
public
String execute()
{
return
"
path
"
;
}
}
struts.xml
<?
xml version="1.0" encoding="UTF-8"
?>
<!
DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"
>
<
struts
>
<!--
Add packages here
-->
<
constant
name
="struts.devMode"
value
="true"
/>
<
package
name
="front"
namespace
="/path"
extends
="struts-default"
>
<
action
name
="path"
class
="com.bebig.struts2.path.action.PathAction"
>
<
result
name
="path"
>
/path.jsp
</
result
>
</
action
>
</
package
>
</
struts
>
web.xml
<?
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"
xmlns:web
="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version
="2.5"
>
<
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.html
</
welcome-file
>
<
welcome-file
>
index.jsp
</
welcome-file
>
</
welcome-file-list
>
</
web-app
>
發表于 2010-10-09 00:05
風林
閱讀(297)
評論(0)
編輯
收藏
引用
所屬分類:
JAVA
、
Struts2
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
相關文章:
[轉]java編程中'為了性能'一些盡量做到的地方
JAVAC命令行錯誤
Java基礎_Collection接口下的子類存儲特性
Android_常用控件使用
Android_Activity&Intent&Layout
Integer自動裝箱、拆箱問題
自定義比較器、排序
JDBC操作實例
常用數據庫的JDBC連接代碼
[轉]J2SE_內部類
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
CALENDER
<
2025年6月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
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
1
2
3
4
5
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
給我留言
查看公開留言
查看私人留言
隨筆分類
jBPM
(rss)
隨筆檔案
2011年7月 (1)
2011年4月 (1)
2011年2月 (1)
2010年11月 (1)
2010年10月 (2)
2010年9月 (3)
2010年8月 (4)
2010年7月 (2)
文章分類
AJAX(2)
(rss)
Android(2)
(rss)
C#(20)
(rss)
C++(6)
(rss)
ckeditor&ckfinder(1)
(rss)
CSS
(rss)
Delphi(2)
(rss)
Hibernate(39)
(rss)
JAVA(95)
(rss)
jQuery(1)
(rss)
JSP(9)
(rss)
Maven(1)
(rss)
MySQL(4)
(rss)
OOP(1)
(rss)
Python(42)
(rss)
Spring(31)
(rss)
SQL Server(4)
(rss)
Struts2(35)
(rss)
SVN(1)
(rss)
Tomcat(1)
(rss)
Ubuntu(1)
(rss)
軟件加解密技術
(rss)
雜文(1)
(rss)
文章檔案
2011年8月 (1)
2011年7月 (3)
2011年6月 (19)
2011年5月 (2)
2011年4月 (1)
2011年2月 (1)
2010年12月 (2)
2010年11月 (21)
2010年10月 (67)
2010年9月 (48)
2010年8月 (37)
2010年7月 (4)
新聞檔案
2010年7月 (1)
相冊
CSS
Hibernate
搜索
最新評論
1.?re: Struts2_三種傳參數方法
方式的發生
--阿飛史蒂夫
2.?re: 在Win7上搭建JSP開發環境
評論內容較長,點擊標題查看
--鄒
3.?re: ckeditor&ckfinder&s2sh集成
評論內容較長,點擊標題查看
--庸幾何
4.?re: 在Win7上搭建JSP開發環境
下個 myeclipse@lou
--孫毅
5.?re: 在Win7上搭建JSP開發環境
@lou
運行 -cmd 找到startup.bat 在java 環境中運行
--孫毅
閱讀排行榜
1.?開始找Java開發類工作了(510)
2.?給一家公司的軟件做加密方案(443)
3.?一流、二流、三流(421)
4.?周一到周五都得出差,周末才能回(420)
5.?最近工作有點忙(381)
評論排行榜
1.?周一到周五都得出差,周末才能回(2)
2.?給力2011(2)
3.?最近工作有點忙(0)
4.?生活(0)
5.?在博客園開博了(0)
Powered By:
博客園
模板提供
:
滬江博客
青青草国产成人久久91网
|
伊人色综合久久天天人守人婷
|
无码久久精品国产亚洲Av影片
|
久久强奷乱码老熟女
|
久久九色综合九色99伊人
|
奇米影视7777久久精品人人爽
|
久久99久国产麻精品66
|
久久99精品国产自在现线小黄鸭
|
99精品伊人久久久大香线蕉
|
色综合久久夜色精品国产
|
丁香狠狠色婷婷久久综合
|
国产高潮久久免费观看
|
av色综合久久天堂av色综合在
|
www亚洲欲色成人久久精品
|
久久99久国产麻精品66
|
久久99精品国产麻豆婷婷
|
久久人人妻人人爽人人爽
|
粉嫩小泬无遮挡久久久久久
|
久久精品成人免费观看97
|
91精品国产色综合久久
|
久久亚洲国产精品成人AV秋霞
|
久久久久亚洲精品天堂久久久久久
|
麻豆精品久久久久久久99蜜桃
|
久久无码国产
|
97久久精品无码一区二区
|
亚洲精品午夜国产va久久
|
久久丝袜精品中文字幕
|
99久久99这里只有免费的精品
|
国内精品久久久久影院老司
|
久久九九久精品国产
|
久久99国产精品成人欧美
|
国产成人精品综合久久久
|
国产亚洲欧美成人久久片
|
国产精品久久久久久一区二区三区
|
久久久久久国产精品美女
|
亚洲国产精品嫩草影院久久
|
国内精品久久久久影院优
|
久久精品国产99国产精品导航
|
亚洲午夜久久久久久噜噜噜
|
色偷偷88欧美精品久久久
|
亚洲国产精品综合久久网络
|