作者:zhengfke | 来源:互联网 | 2023-05-17 09:04
使用Struts2关键的是struts.xml和web.xml文件的配置,这里我主要讲解struts.xml文件;调用方法的方法主要有三种:第一种方式:在struts.文件下的package
使用Struts2关键的是struts.xml和web.xml文件的配置,这里我主要讲解struts.xml文件;调用方法的方法主要有三种:
第一种方式:在struts.文件下的package包下面配置action,里面有几个方法就调用几次例如:
class="com.imooc.action.HelloAction">
/result.jsp
class="com.imooc.action.HelloAction">
/add.jsp
访问add.JSP页面方式:localhost:8080/HelloWorld/add.action.
这种方式在方法多的情况下不推荐使用
第二种方式:调用感叹号的方式,此时需要我们在struts.xml下的增加例:
struts>
/result.jsp
/add.jsp
/indexx.jsp
访问add.jsp页面方式:localhost:8080/Hello/hello!add.action
第三种方式:也就是最常用的,官方推荐使用:通配符方式:
/result.jsp
/{1}.jsp
/{1}.jsp
我们需要给action的name添加_和* 然后添加一个Method”{1}“,{1}代表_后面的*参数,这种方法更简便:
同样访问index.jsp页面的方式:localhost:8080/Hello_add.action