pues personalmente utilizo puro JSON, no me gusta regresar HTML por que en el lado del servidor se hace un cochinero :d, en cambio con json en el servidor queda algo asi:
   Código PHP:
    public ModelAndView guardarMateria(HttpServletRequest request, HttpServletResponse response, MateriaForm command) throws Exception {
        JSONObject json = new JSONObject();
        Boolean isNew = command.getIdMateria()==null || "".equals(command.getIdMateria());
        
        try{
            Institucion institucion = getInstitucion(request);
            Materia materia;
            if(isNew){
                materia = new Materia(null,new Nivel(command.getIdNivel()),CharUtil.fixIsoCharacters(command.getNombre()),new Boolean(true));
                materia.getNivel().setInstitucion(institucion);
                materiaMgr.guardarMateria(materia);
                json.put("success", true);
                json.put("msg",getMessage("materia.msg.materiaGuardada"));
            }else{
                materia = new Materia(command.getIdMateria(),new Nivel(command.getIdNivel()),CharUtil.fixIsoCharacters(command.getNombre()),new Boolean(true));
                materiaMgr.actualizarMateria(materia);
                json.put("success", true);
                json.put("msg",getMessage("materia.msg.materiaActualizada"));
            }
        }catch(RowAlreadyExistsException ee){
            log.debug(ee.toString());
            json.put("success", false);
            json.put("msg",getMessage("materia.msg.yaExiste"));
        }catch(Exception e){
            log.debug(e.toString());
            json.put("success", false);
            json.put("msg",e.getMessage());
        }
        
        response.setHeader("Content-Type", "text/plain");
        response.getWriter().print(json.toString());
        return null;
    } 
    
  utilizando apis de JSON, como "JSONObject", el código queda muy limpio :D 
saludos