struts2 _ action基本配置_路径问题
//IndexAction。java
public class IndexAction extends ActionSupport {
public String execute() {
return "success";
}
}
//对应的struts.xml
<package name="front" extends="struts-default" namespace="/">
<action name="index" extends="struts-default" namespace="/user">
<action name="user" extends="struts-default" namespace="/actions">
<action name="Student*" method="{1}">
<result>/Student{1}_success.jsp</result>
</action>
<action name="*_*" method="{2}">
<result>/{1}_{2}_success.jsp</result>
</action>
</package> 其中"{1}”表示第1个*号,"{2}”表示第2个*号,以此类推
2) 路径问题
struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径
虽然可以用redirect方式解决,但redirect方式并非必要。
解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式来拿到webapp的路径)
或者使用myeclipse经常用的,指定basePath
解决办法:
加入:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+
request.getServerName()+":"+request.getServerPort()+path+"/";
%>
在<head>标签后加入
<base href="<%=basePath%>" />
这样,这个页面中所的连接,jsp都会帮忙加上:http://localhost:8080/appricationName/ (类似这样的东西)