StringMVC返回字符串
@RequestMapping(value="twoB.do") public void twoBCode(HttpServletRequest request,HttpServletResponse response) { //.......... 此处省略 N行 try { response.setContentType("type=text/html;charset=UTF-8"); String s = "一堆字符串......"; response.getWriter().write(s); } catch (Exception e) { e.printStackTrace(); } return; }
SpringMVC返回字符串的方法有好多,来个简单粗暴的方法:
使用@ResponseBody 注解返回字符串
@RequestMapping(value="getJosn.do", produces="text/html;charset=UTF-8") @ResponseBody public String getTabJson(){ String json = "{"无主题":"http://www.wuzhuti.cn"}"; return json; }