controller中的变量值,直接在浏览器中显示,无需jsp页面

来源:互联网 发布:包装版面设计软件 编辑:程序博客网 时间:2024/05/22 06:15

目的:在web开发中,如果想不通过jsp页面,将controller中的数据展示出来,可以直接在浏览器中展示。

1.首先在controller中写下面的代码

/** * 查询数据库中所有的算法 * @param request * @param response * @return */@RequestMapping("/findAlgorithmResult/{inputString}")@ResponseBodypublic List<Algorithm> findAllAlgorithms(HttpServletRequest request, HttpServletResponse response, @PathVariable(value="inputString")String inputString) throws Exception {PrintWriter out = response.getWriter();try{out.print(inputString);}catch(Exception e) {e.printStackTrace();}return null;}
2.在controller中写上述代码,然后启动Tomcat服务器;

3.启动好服务器以后,在浏览器中输入:http://localhost:8080/项目名/findAlgorithmResult/123455.controller即可在浏览器中看到 输入的字符串了;

上述方法无需通过jsp页面展示controller中的数据,可以用于在一个项目AAA中,获取另一个网站BBB的数据;上述的方法即可以用做项目BBB的内容。
(完毕)

 
阅读全文
0 0
原创粉丝点击