标签:xtend mapping com 等于 inf info struts2 图片 form
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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>*.action</url-pattern> </filter-mapping> </web-app>
是过滤为后缀为action
struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="default" extends="struts-default" namespace="/" > <action name="BookAction" class="servlet.BookAction"> <result name="Success">/list.jsp</result> <result name="Error">/add.jsp</result> </action> </package> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> </struts>
动态方法调用:
<form action="BookAction!add.action" method="post">
动态方法调用是指:表单元素的action不直接等于某个Action的名字,而是以感叹号后加方法名来指定对应的动作名:
这里用动态方法还需在struts里添加
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
在action里用
public String execute() { return "";//默认为execute,有具体的方法,调用具体的方法,这里调用add方法。 } public String add() { return "" }
标签:xtend mapping com 等于 inf info struts2 图片 form
原文地址:https://www.cnblogs.com/zlj843767688/p/12625276.html