隨筆: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年7月
>
日
一
二
三
四
五
六
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
5
6
7
8
9
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
給我留言
查看公開留言
查看私人留言
隨筆分類
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:
博客園
模板提供
:
滬江博客
久久天天躁狠狠躁夜夜avapp
|
伊人久久五月天
|
久久国产精品无码一区二区三区
|
亚洲AV无码一区东京热久久
|
午夜精品久久久久久久
|
久久精品国产91久久综合麻豆自制
|
久久99精品久久久久久不卡
|
久久人人超碰精品CAOPOREN
|
久久精品国产2020
|
日本久久久久久中文字幕
|
久久精品日日躁夜夜躁欧美
|
欧美精品一本久久男人的天堂
|
久久久午夜精品
|
久久99热狠狠色精品一区
|
久久久久亚洲AV无码观看
|
超级碰久久免费公开视频
|
亚洲AV日韩AV永久无码久久
|
久久91这里精品国产2020
|
久久精品麻豆日日躁夜夜躁
|
久久嫩草影院免费看夜色
|
91久久精一区二区三区大全
|
亚洲va久久久久
|
久久久久一本毛久久久
|
国产日产久久高清欧美一区
|
色诱久久久久综合网ywww
|
欧美伊人久久大香线蕉综合
|
久久免费视频6
|
综合久久一区二区三区
|
69国产成人综合久久精品
|
性做久久久久久久久老女人
|
亚洲国产精品久久久久婷婷老年
|
国产精品对白刺激久久久
|
色偷偷88888欧美精品久久久
|
精品国产99久久久久久麻豆
|
亚洲精品成人网久久久久久
|
久久国产精品视频
|
久久天天躁狠狠躁夜夜av浪潮
|
久久国产精品免费一区二区三区
|
久久精品国产清自在天天线
|
久久高清一级毛片
|
无夜精品久久久久久
|