import java.io.File;
import java.io.FileWriter;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
private String fail_view;
private IUrlsService urlsService;
public void setFail_view(String fail_view) {
this.fail_view = fail_view;
}
this.success_view = success_view;
}
public void setUrlsService(IUrlsService urlsService) {
this.urlsService = urlsService;
}
HttpServletResponse response) throws Exception {
String urls=urlsService.getUrls("html");
String filePath="F:/urlFile";
try{
File myFilePath = new File(filePath);
if (!myFilePath.exists()) {
myFilePath.mkdirs();
}
FileWriter write=new FileWriter(filePath+"/htmlUrl.txt");
BufferedWriter writer=new BufferedWriter(write);
writer.write(urls);
writer.flush();
String success = "生成成功";
writer.close();
writer.close();
return new ModelAndView(this.success_view,"success",success);
}catch(Exception e){
String fail = "生成失败";
return new ModelAndView(this.fail_view, "fail", fail);
}
}
public ModelAndView ubbFile(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String urls=urlsService.getUrls("ubb");
String filePath="F:/urlFile";
try{
File myFilePath = new File(filePath);
if (!myFilePath.exists()) {
myFilePath.mkdirs();
}
FileWriter write=new FileWriter(filePath+"/ubbUrl.txt");
BufferedWriter writer=new BufferedWriter(write);
writer.write(urls);
writer.flush();
String success = "生成成功";
writer.close();
writer.close();
return new ModelAndView(this.success_view,"success",success);
}catch(Exception e){
String fail = "生成失败";
return new ModelAndView(this.fail_view, "fail", fail);
}
}
}
<property name="paramName">
<value>method</value>
</property>
<property name="defaultMethodName">
<value>htmlFile</value>
</property>
<property name="fail_view">
<value>fail</value>
</property>
<property name="success_view">
<value>success</value>
</property>
<property name="urlsService">
<ref bean="urlsService" />
</property>
<property name="methodNameResolver">
<ref bean="methodNameResolver"/>
</property>
</bean>
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<!-- <property name="defaultHandler" ref="urlFileBuildAction"/>-->
<property name="mappings">
<props>
</props>
</property>
</bean>
二、使用PropertiesMethodNameResolver
1、配置applicatonContext.xml
<bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/urlhtmlFileBuildAction.do">htmlFile</prop>
<prop key="/urlubbFileBuildAction.do">ubbFile</prop>
</props>
</property>
</bean>
2、配置applicatonContext-action.xml
<bean id="handlerMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="defaultHandler" ref=" sampleMultiMethodController "/>
</bean>
<bean id="urlFileBuildAction" class="org.dispenseModule.web.UrlFileBuildAction">
<property name="fail_view">
<value>fail</value>
</property>
<property name="success_view">
<value>success</value>
</property>
<property name="urlsService">
<ref bean="urlsService" />
</property>
<property name="methodNameResolver">
<ref bean="methodNameResolver"/>
</property>
</bean>
使用urlhtmlFileBuildAction.do