导入axios包
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
页面发起请求
axios作为网页端的接口可以在页面发起get请求
axios.get('url')
通过这条语句可以调用来自url的返回数据,如果来自‘url’的是JSON形式的此时List数组内部就被传入了来自‘url’的数据。
axios.get('url').then((res)=>{
this.List=res.data
})
向后端传输active
为了提高程序的内聚时同一个controler需要处理多种的数据操作,我们需要在页面上向后端发起不同的请求来实现功能的内聚
html端
axios.get('/FileC?active=getFileName').then((res)=>{
this.List=res.data
})
controler端
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
String action=req.getParameter('action')
if("getFileName".equals(action)){
//要执行的数据操作
}
}