struts2的package跳转问题

类似于这种链接:
http://localhost:9090/interface/6
后面的数字动态的
下面是struts.xml的配置:

 <struts>
    <package name="interface2" extends="struts-default" namespace="/interface">
        <default-interceptor-ref name="basicStack"></default-interceptor-ref>
        <action name="sync" class="interfaceAction">
            <result>/WEB-INF/jsp/interface/response.jsp</result>
        </action>
        <action name="req" class="interfaceRequestAction"></action>
    </package>
</struts>

通过上面的链接,需要跳转到req,本人对struts2不是很熟,帮忙看看有什么问题

<package name="basicQuery" namespace="/basicQuery" extends="struts-default">


/jsp/basicQuery/placeConsume.jsp


其中package 中的namespace就是你要配置的interface。
action中的class就是你要执行的那个action方法全部限定(包括包名),method中的BasicInfoQuery就是你要执行的方法的后缀名
result中的name就是你的action中返回的字符串,根据此返回值,跳转到相应的jsp或者其他你想要的其他界面,你对应的改改就行。希望能帮到你图片说明

interface/req.action
并且书写对应的class路径,以及method

struts2框架是控制层的一个优秀实现。可以控制页面跳转。以action类作为后端基础。

假如你的struts2配置文件是



/WEB-INF/jsp/interface/response.jsp



action的代码结构就是
public class interfaceAction extends ActionSupport{

public String hello() throws Exception {
    return SUCCESS;
}

}

很明显你的配置文件文件没有method 表示:这个action执行interfaceAction类的hello方法

你说的最重要的问题,在这个配置文件里,的名字都是自己决定的,相当于起了个外号的作用。但是

namespace=“/”我们一般都这样设置,在URL访问时http://192.168.1.107/testprograme/sync.action----testprograme为Web项目名;/ 为namespace;sync为我们在配置文件里的action=sync

假如你的namespace="/interface"时,你的URL也会变http://192.168.1.107/testprograme/interface/sync.action




/jsp/basicQuery/placeConsume.jsp


其中package 中的namespace就是你要配置的interface。
action中的class就是你要执行的那个action方法全部限定(包括包名),method中的BasicInfoQuery就是你要执行的方法的后缀名
result中的name就是你的action中返回的字符串,根据此返回值,跳转到相应的jsp或者其他你想要的其他界面,你对应的改改就行。希望能帮到你